JS響應回車事件

(1)監聽某個輸入框spa

    $('#search_input').bind('keyup', function(event) {

        if (event.keyCode == "13") {

            //回車執行查詢

            $('#search_button').click();

        }

});

 

(2)監聽某個區域code

$("#queryTable").bind("keydown",function(e){

          // 兼容FF和IE和Opera   

             var theEvent = e || window.event;   

             var code = theEvent.keyCode || theEvent.which || theEvent.charCode;   

             if (code == 13) {   

                 //回車執行查詢

            $("#queryButton").click();

        }   

});

 

(3)監聽bodyblog

//回車事件

    document.onkeydown = function (event) {

        var e = event || window.event;

        if (e && e.keyCode == 13) { //回車鍵的鍵值爲13

            $("#login").click(); //調用登陸按鈕的登陸事件

        }

    };
相關文章
相關標籤/搜索