This article mainly introduces jQuery shortcut methods such as disabling keyboard rewind, shielding F5 refresh, and disabling right-click, if you are interested, refer to the examples in this article to introduce four methods for jquery to disable multiple functions.
1. disable F5 to refresh jQuery instance code
F5 has the ability to refresh the web page, and may sometimes need to disable this function. The following describes how to implement this function through code instances.
The code is as follows:
$(document).ready(function(){ $(document).bind("keydown",function(e){ var e=window.event||e; if(e.keyCode==116){ e.keyCode = 0; return false; } }) })
2. jQuery disables shortcut keys such as keyboard rewind and F5 refresh
$ (Document ). keydown (function (event) {// mask Alt + direction key ↓ // mask Alt + direction key → if (event. altKey) & (event. keyCode = 37) | (event. keyCode = 39) {event. returnValue = false; return false;} // block the unsigned deletion key if (event. keyCode = 8) {return false;} // block the F5 refresh key if (event. keyCode = 116) {return false;} // block alt + R if (event. ctrlKey) & (event. keyCode = 82) {return false ;}});
3. disable the right-click function
The code is as follows:
$(document).ready(function() { $(document).bind("contextmenu",function(e) { alert("sorry! No right-clicking!"); return false; }); });
4. jQuery's implementation code to prevent page bounce
$(document).keydown(function (e) { var doPrevent; if (e.keyCode == 8) { var d = e.srcElement || e.target; if (d.tagName.toUpperCase() == 'INPUT' || d.tagName.toUpperCase() == 'TEXTAREA') { doPrevent = d.readOnly || d.disabled; } else doPrevent = true; } else doPrevent = false; if (doPrevent) e.preventDefault(); });
The above is all the content of this article, hoping to help you learn.