<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>
<body onkeydown="if(event.keyCode==13)return false;">
添加body的一个onkeydown事件,判断其是否按下回车键,按下的话返回false可能代表没按回车。
<body onkeydown="keydown()">
<form>
<input name="word" type="text" value="关键字" size="9" onclick="javascript:return false();">
<input type=submit value=ok name=ok>
</form>
<script language="JavaScript"><!--
function keydown() {
var k = window.event.keyCode;
var e = window.event.srcElement;
if (e.type == "text" && k == 13) {
window.event.keyCode = 0;
window.event.returnValue = false;
}
}
//--></script>
JavaScript-Tips,布布扣,bubuko.com
原文:http://www.cnblogs.com/RocCnBlog/p/3820500.html