方法一:
// 禁用右鍵菜單、復制、選擇$(document).bind("contextmenu copy selectstart", function() { return false;});
方法二:
// 禁用Ctrl+C和Ctrl+V(所有瀏覽器均支持)$(document).keydown(function(e) { if(e.ctrlKey && (e.keyCode == 65 || e.keyCode == 67)) { return false; }});
方法三:
// 設置CSS禁止選擇(如果寫了下面的CSS則不需要這一段代碼,新版瀏覽器支持)$(function() { $("body").css({ "-moz-user-select":"none", "-webkit-user-select":"none", "-ms-user-select":"none", "-khtml-user-select":"none", "-o-user-select":"none", "user-select":"none" });});
方法四:防止禁用JavaScript后失效,可以寫在CSS中(新版瀏覽器支持,并逐漸成為標準):
body { -moz-user-select:none; /* Firefox私有屬性 */ -webkit-user-select:none; /* WebKit內核私有屬性 */ -ms-user-select:none; /* IE私有屬性(IE10及以后) */ -khtml-user-select:none; /* KHTML內核私有屬性 */ -o-user-select:none; /* Opera私有屬性 */ user-select:none; /* CSS3屬性 */}
|
新聞熱點
疑難解答