一)表單裏面的提交,一般都支持回車提交的。
① form 裏面單個 input 控件
<form action="http://www.csdn.cn">
<input type="text" />
</form>
② form 裏面多個個 input 控件 用 <input type="submit" /> 提交
<form action="http://www.csdn.net">
<input type="text" />
<input type="text" />
<input type="submit" />
</form>
③ form 裏面多個個 input 控件 用 button 提交
<form action="http://www.csdn.net">
<input type="text" />
<input type="text" />
<button>確定</button>
</form>
注意:上面三種提交都必須要先獲取焦點,也就是在回車提交之前把光標定位到 <input type="text" />
二)js onclick 觸發
① <input type="submit" /> 支持回車觸發 onclick 只適用於 IE
<input type="submit" value="確認註冊" onclick="reg_ck();" />
② jQuery 捕獲回車事件
$("input").keydown(function(e){ //捕捉回車事件
var curKey = e.which;
if(curKey == 13){
要執行的函數();
}
});
注意:js onclick 觸發 的情況下,①和② 不能同時存在,不然會提交兩次