那么我正在尝试通过按Enter键提交表单,但不显示提交按钮。 如果可能,我不想进入JavaScript,因为我希望所有浏览器都可以使用所有浏览器(我唯一知道的JS方式是使用事件)。
现在的形式如下:
<form name="loginBox" target="#here" method="post"> <input name="username" type="text" /><br /> <input name="password" type="password" /> <input type="submit" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" /> </form>哪个工作相当不错 当用户按下Enter键时,提交按钮可以工作,该按钮不会显示在Firefox,IE,Safari,Opera和Chrome中。 但是,我仍然不喜欢这个解决方案,因为它很难知道它是否能在所有浏览器的所有平台上运行。
任何人都可以提出更好的方法吗 或者这是关于它得到的好吗?
Well I am trying to submit a form by pressing enter but not displaying a submit button. I don't want to get into JavaScript if possible since I want everything to work on all browsers (the only JS way I know is with events).
Right now the form looks like this:
<form name="loginBox" target="#here" method="post"> <input name="username" type="text" /><br /> <input name="password" type="password" /> <input type="submit" style="height: 0px; width: 0px; border: none; padding: 0px;" hidefocus="true" /> </form>Which works pretty well. The submit button works when the user presses enter, and the button doesn't show in Firefox, IE, Safari, Opera and Chrome. However, I still don't like the solution since it is hard to know whether it will work on all platforms with all browsers.
Can anyone suggest a better method? Or is this about as good as it gets?
最满意答案
尝试:
<input type="submit" style="position: absolute; left: -9999px"/>这将把按钮waaay向左推出屏幕。 这样做的好处是,当CSS被禁用时,你会得到优雅的降级。
更新 - IE7的解决方法
如Bryan Downing +与tabindex建议,以防止tab达到此按钮(由Ates Goral):
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" tabindex="-1" />Try:
<input type="submit" style="position: absolute; left: -9999px"/>That will push the button waaay to the left, out of the screen. The nice thing with this is, you'd get graceful degradation when CSS is disabled.
Update - Workaround for IE7
As suggested by Bryan Downing + with tabindex to prevent tab reach this button (by Ates Goral):
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" tabindex="-1" />更多推荐
submit,button,电脑培训,计算机培训,IT培训"/> <meta name="description&quo
发布评论