屏蔽右键问题
- HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><style> body{ margin:0; padding:0; font-size:12px; background:#fff} .main{ width:960px; margin:auto; overflow:hidden; background:#D9D9D9}</style><script src="js/jquery-1.6.4.min.js" type="text/javascript"></script><script type="text/javascript">$(document).ready(function(){ text();});function text(){ var $text = $("#text"); $text.mouseover(function(){ $("body").attr({"onselectstart":"return true;","oncontextmenu":"return true;"}) }).mouseout(function(){ $("body").attr({"onselectstart":"return false;","oncontextmenu":"return false;"}) })}</script></head><body onselectstart="return false;" oncontextmenu="return false;"> <div class="main"> <textarea id="text" name="" cols="" rows="" style="width:300px; height:200px"></textarea> </div></body></html>
我想实现的效果,一开始鼠标右键是屏蔽的,当鼠标移入文本框时鼠标右键就恢复,当鼠标移离文本框时鼠标右键就屏蔽,上面的代码IE8,9都行,就是IE7不行,请各位帮助看一下是什么原因,谢谢。
[解决办法]
- HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gbk" /><title></title><style> body{ margin:0; padding:0; font-size:12px; background:#fff} .main{ width:960px; margin:auto; overflow:hidden; background:#D9D9D9}</style><script src="http://code.jquery.com/jquery-latest.js"></script><script type="text/javascript">$(document).ready(function(){ text();});function text(){ var $text = $("#text"); $text.mouseover(function(){ document.oncontextmenu = null; }).mouseout(function(){ document.oncontextmenu = function (event){ var event = event || window.event; return false; }; })}document.oncontextmenu = function (event){ var event = event || window.event; return false;};</script></head><body> <div class="main"> <textarea id="text" name="" cols="" rows="" style="width:300px; height:200px"></textarea> </div></body></html>
[解决办法]
http://www.codingforums.com/showthread.php?t=150345