jQuery禁用鍵盤后退屏蔽F5刷新及禁用右鍵單擊
更新時間:2016年01月22日 09:07:32 投稿:lijiao
這篇文章主要介紹了jQuery禁用鍵盤后退、屏蔽F5刷新、禁用右鍵單擊功能等快捷方法,感興趣的小伙伴們可以參考一下
本文實例介紹了四種jquery禁用多種功能的方法
1、禁用F5刷新jQuery實例代碼
F5具有刷新網(wǎng)頁的功能,可能有時候需要禁用此功能,下面就通過代碼實例介紹一下如何實現(xiàn)此功能。
代碼如下:
$(document).ready(function(){ $(document).bind("keydown",function(e){ var e=window.event||e; if(e.keyCode==116){ e.keyCode = 0; return false; } }) })
2、jQuery禁用鍵盤后退、F5刷新等快捷鍵
$(document).keydown(function(event){ //屏蔽 Alt+ 方向鍵 ← //屏蔽 Alt+ 方向鍵 → if ((event.altKey)&&((event.keyCode==37)||(event.keyCode==39))) { event.returnValue=false; return false; } //屏蔽退格刪除鍵 if(event.keyCode==8){ return false; } //屏蔽F5刷新鍵 if(event.keyCode==116){ return false; } //屏蔽alt+R if((event.ctrlKey) && (event.keyCode==82)){ return false; } });
3、禁用右鍵單擊功能
代碼如下:
$(document).ready(function() { $(document).bind("contextmenu",function(e) { alert("sorry! No right-clicking!"); return false; }); });
4、jQuery防止退格鍵網(wǎng)頁后退的實現(xiàn)代碼
$(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(); });
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助。
相關文章
jQuery基于事件控制實現(xiàn)點擊顯示內(nèi)容下拉效果
這篇文章主要介紹了jQuery基于事件控制實現(xiàn)點擊顯示內(nèi)容下拉效果,涉及jQuery事件響應及元素屬性動態(tài)操作相關技巧,需要的朋友可以參考下2017-03-03jquery ajaxfileupload異步上傳插件使用詳解
這篇文章主要為大家詳細介紹了jquery ajaxfileupload異步上傳插件的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02基于JQuery和CSS3實現(xiàn)仿Apple TV海報背景視覺差特效源碼分享
這是一款效果非常炫酷的jQuery和CSS3仿Apple TV海報背景視覺差特效。該視覺差特效在使用鼠標在屏幕上下左右移動的時候,海報中的各種元素以不同的速度運動,形成視覺差效果,并且還帶有一些流光特效。2015-09-09