1. 程式人生 > >按鈕接受回車事件的三種實現方法

按鈕接受回車事件的三種實現方法

方法一:
<script type="text/javascript" event="onkeydown" for="document"> 
if(event.keyCode==13) 
{ 
var button=document.all("<%=ButtonAddorUpdate.ClientID %>"); 
button.focus(); 
button.click(); 
} 
</script> 
方法二:
<input type="button" onclick="noClick()" style="margin-top:-1024px;" id="noUseButton" /> 
<script type="text/javascript" event="onkeydown" for="document"> 
if(event.keyCode==13) 
{ 
var button=document.getElementById("noUseButton"); 
button.focus(); 
button.onclick(); 
} 
</script> 
<script> 
function noClick() 
{ 
return false; 
} 
</script>
方法三:
遮蔽頁面回車事件 ,在Form標識中加入如下內容:
method="post" onkeydown="if(event.keyCode==13) return false;"