在輸入框中輸入回車執行動作也算頁面控件常用操作項之一了,故把代碼整理出來放在這里。
代碼:
<!DOCTYPE html>
<html lang="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<head>
<title>標題</title>
<style type="text/css">
/*CSS樣式*/
</style>
</head>
<body>
<input type="text" onkeypress="actionOnEnter(event);"/>
</body>
</html>
<script type="text/javascript">
<!--
function actionOnEnter(evt){
evt=evt?evt:event;
var charCode=(evt.charCode)?evt.charCode:((evt.which)?evt.which:evt.keyCode);
if(charCode==13 || charCode==3){
doBusiness();
}
}
function doBusiness(){
alert("biz");
}
//-->
</script>
以上粗體文本為關鍵代碼。
END

