js 热键提交表单

回车提交表单
<script>
document.onkeydown=function(event){
    e = event ? event : (window.event ? window.event : null);
    if(e.keyCode==13){
    //执行的方法
    alert('回车检测到了');
    }
}
</script>
回车禁止提交功能(ie9,firefox,ie8,chrome测试通过)
html
<input type="text" name="checkcode" onkeypress="return doClick(event);"/>
//铵enter键,阻止提交订单
function doClick(event) {
    var key;
    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = event.which;     //firefox

    if (key == 13) {
        try {
            if (window.event) {//ie
                window.event.keyCode = 0
                window.event.returnValue = false;
            }
            else {//firefox
                return false;
            }
        }
        catch (ex) {
        }
    }
}
 

 

你可能感兴趣的:(Opera)