通过在没有提交按钮的情况下按Enter来提交表单嗯,我试图提交一个表格,按下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键时,Submit按钮工作,并且该按钮在Firefox、IE、Safari、Opera和Chrome中不显示。但是,我仍然不喜欢这个解决方案,因为很难知道它是否能在所有浏览器的平台上工作。有人能提出更好的方法吗?还是像现在一样好?
3 回答
慕妹3146593
TA贡献1820条经验 获得超9个赞
<input type="submit" style="position: absolute; left: -9999px"/>
更新-IE7的解决方案
tabindex
<input type="submit" style="position: absolute; left: -9999px; width: 1px; height: 1px;" tabindex="-1" />
翻过高山走不出你
TA贡献1875条经验 获得超3个赞
<script type="text/javascript">// Using jQuery.$(function() { $('form').each(function() { $(this).find('input').keypress(function(e) { // Enter pressed? if(e.which == 10 || e.which == 13) { this.form.submit(); } }); $(this).find('input[type=submit]').hide(); });});</script><form name="loginBox" target="#here" method="post"> <input name="username" type="text" /><br /> <input name="password" type="password" /> <input type="submit" /></form>
神不在的星期二
TA贡献1963条经验 获得超6个赞
<input type="submit" style="visibility: hidden;" />
visibility:hidden
display:none
- 3 回答
- 0 关注
- 473 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消