首頁 >web前端 >js教程 >javascript禁制後退鍵(Backspace)實例程式碼_javascript技巧

javascript禁制後退鍵(Backspace)實例程式碼_javascript技巧

WBOY
WBOY原創
2016-05-16 17:14:57941瀏覽
複製碼 程式碼如下:

function banBackSpace || window.event;//取得event物件 
                var obj = ev.target || ev.srcElement                   //獲取作為判斷條件的事件類型 
                var vReadOnly = obj.readOnly; 
                var vDisabled = obj.disabled; 
                //處理undefined值情況 
                vReadOnly = (vReadOnly == undefined) ? false : vReadOnly; 
                         //當敲Backspace鍵時,事件來源類型為密碼或單行、多行文本的, 
                //且readOnly屬性為true或disabled屬性為true的,則退格鍵失效 
     "password" || t == " text" || t == "textarea") && (vReadOnly == true || vDisabled == true); 
              退格鍵失效 
                var flag2 = ev.keyCode == 8 && t != "password" &     //判斷 
                if (flag2 || flag1) return false 

            } 
         document.onkeypress = banBackSpace; 
            //以IE、Chrome
            document.onkeydown = banBackSpace; 

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn