2012-01-10 284 views

回答

11

您不能禁用擊鍵這樣,但你可以用jQuery捕獲並覆蓋其行爲(返回false)。下面的示例捕獲輸入密鑰。只需將13更改爲您需要禁用的任何鍵碼。

$("input").keypress(function (evt) { 

    var keycode = evt.charCode || evt.keyCode; 
    if (keycode == 13) { //Enter key's keycode 
    return false; 
    } 
}); 
+1

剛剛意識到會捕獲輸入字段。如果你想禁用整個頁面,將「input」改爲「body」。 – detheridge02 2012-01-10 14:54:18

1

處理onKeyDown,然後preventDefault就可以了。

0

只需添加一個OnKeyUp,Down-EventListener到你的HTML頁面,如果按下的鍵是要忽略你剛纔preventDefault

1

我能想到的是這樣的:通過返回false你告訴瀏覽器不允許按下的鍵事件

6

我不得不關閉所有的鑰匙,但

// Bind this keypress function to the html (not sure about this) or body tags of your page 
$("body").keypress(function (evt) { 
//Determine where the character code is coming from 
var charCode = evt.charCode || evt.keyCode; 

if (charCode == 13) { //Enter key's keycode, could be any other key 
return false; 
} 
}); 

F11和ESC。所以我這樣做了。認爲這可能有助於某人。 :)

$(document).on('keydown',function(e) 
{ 
    var key = e.charCode || e.keyCode; 
    if(key == 122 || key == 27) 
     {} 
    else 
     e.preventDefault(); 
}); 
+0

其有用的,但它不工作在PrtSc屏幕,actully我想用這個沒有人可以保存我的網頁,甚至沒有截圖,如果你可以plz幫助 – sunil 2016-11-11 08:06:01