js處理backspace和enter鍵


<script language="javascript" type="text/javascript">
    //處理鍵盤事件
    function doKey(e) {
        var ev = e || window.event; //獲取event對象  
        var obj = ev.target || ev.srcElement; //獲取事件源  
        var t = obj.type || obj.getAttribute('type'); //獲取事件源類型  
        if (ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea") {
            return false;
        }
        if (ev.keyCode == 13) {
            GetSearch();
            return false;
        }
    }
    //禁止后退鍵 作用於Firefox、Opera  
    document.onkeypress=doKey;  
    //禁止后退鍵  作用於IE、Chrome  
    document.onkeydown=doKey;
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM