1.在页面按回车键后触发js的执行
2.阻止表单提交
3.判断光标是否在某个控件上
<script type="text/javascript">
//防止提交表单
document.getElementById("fm").onsubmit = function(e){
return false;
};
document.getElementById("fm2").onsubmit = function(e){
return false;
};
document.onkeydown = function(e){
if(!e) e = window.event;//火狐中是 window.event
if((e.keyCode || e.which) == 13){
if(document.activeElement.id=="mobile"){//光标停留在id为mobile的控件上
initPage.getUserProduct();
}
if(document.activeElement.id=="searchParam"){
var searchParam=$("#searchParam").val();
jQuery.cookie("searchParam", searchParam, {path: '/' });
location="list.html";
}
}
}
</script>