用jQuery屏蔽掉按回车键时提交表单
默认情况下,在表单输入框里按回车将会提交表单,但有时需要屏蔽掉按回车键提交表单功能,以保证完整输入表单,如何做呢?
解决办法:
<script type="text/javascript"> $(function() { $("input").keypress(function (e) { var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode; if (keyCode == 13) { for (var i = 0; i < this.form.elements.length; i++) { if (this == this.form.elements[i]) break; } i = (i + 1) % this.form.elements.length; this.form.elements[i].focus(); return false; } else { return true; } ); }); </script>
相关推荐
JINKAI 2011-10-26
wustrive00 2014-01-03
卡奇莫多 2013-08-29
haleyyan 2011-12-27
maple00 2011-04-15
onethousand 2018-11-26
cjwsohu 2018-03-09
83453861 2017-11-21
zgwyfz 2019-04-26
demon00d 2019-04-26
stonerkuang 2019-04-25
87941037 2015-12-24
ericwuhk 2009-09-09
83457500 2019-04-18
83457500 2014-05-11
yaasshole 2014-05-11