$(function () {
//定义回车事件
if (document.addEventListener) {//如果是Firefox
document.addEventListener("keypress", fireFoxHandler, true);
}
else {
document.attachEvent("onkeypress", ieHandler);
}
function fireFoxHandler(evt) {
if (evt.keyCode == 13) {
$("#btnLogin")[0].click();
}
}
function ieHandler(evt) {
if (evt.keyCode == 13) {
$("#btnLogin")[0].click();
}
}
});
单个文本框实现:
$("#txt_sname").keydown(function(e){
var curKey = e.which;
if (curKey == 13) {
$("#btn_search").click();
return false;
}
});
转自:
http://blog.csdn.net/dannywj1371/article/details/7603678