firefox下禁止鼠标中键事件无效
大家好,我想禁止页面中的鼠标中键点击拖曳的动作
所以就想禁止页面中的鼠标中键点击,写了这个函数,在IE CHROME都OK
但是FF没有作用,FF已经判断到了e.which为2,能打印出1,但是依然能拖曳
让我很惆怅,已经在网上搜了很多时间,没有解决方法
不是伸手党,努力无果,求高手指点...谢谢
$(function(){
$(window).mousedown(function(e){
if(e.which == 2) // 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键
alert("1");
return false;//阻止链接跳转
})
return false;
})
$(function() {
$(window).mousedown(function(e) {
if (e.which == 2) { // 1 = 鼠标左键 left; 2 = 鼠标中键; 3 = 鼠标右键
//alert(e.cancelable); //true,说明该事件是可以被取消的
e.preventDefault();
return false; //阻止链接跳转
}
});
return false;
});
<!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=gb2312" />
<title>拖动</title>
<style type="text/css">
*{ margin:0; padding:0;}
html,body{ height:100%; width:100%; font-size:12px;}
#picrun{ position:absolute; top:10px; height:100px; left:100px; width:500px; overflow:hidden;}
#picrun li{ list-style:none; float:left; margin-left:12px; text-align:center; background:#FFF; width:100px;}
#picrun img{ width:100px; height:60px; border:none;display:block; padding-bottom:3px;}
</style>
</head>
<body>
<div id="container">
</div>
<div id="picrun">
<ul id="li_img">
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>1这里哪个厅</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>2哪个厅这个</li>
<li><a href="http://www.baidu.com"><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>3这里哪个厅</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>4哪个厅这个</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>5这里哪个厅</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>6哪个厅这个</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>7这里哪个厅</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>8哪个厅这个</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>这里哪个厅</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>哪个厅这个</li>
<li><a href=""><img src="//img.reader8.com/uploadfile/2014/0313/20140313100331738.gif" /></a>这里哪个厅</li>
</ul>
</div>
<script type="text/javascript">
var picrun=document.getElementById("picrun");
var li_img=document.getElementById("li_img");
var li=li_img.getElementsByTagName("li");
var ig=li_img.getElementsByTagName("img");
var li_w=li[0].clientWidth+12;
li_img.style.width=li_w*li.length+"px";
function Move(o, e){
var e = window.event
[解决办法]
e;
var _sx = e.clientX;
var _xx = picrun.scrollLeft;
document.onmouseup = function(){
this.onmousemove = null;
}
if(e.preventDefault){
e.preventDefault();
}
document.onmousemove = function(e){
var e = window.event
[解决办法]
e;
if(document.all && e.button == 0){
this.onmousemove = null;
return false;
};
picrun.scrollLeft =_xx - e.clientX + _sx;
o.setAttribute('IsMove', 'true');
return false;
}
}
for(i=0;i<ig.length;i++){
(function(n){
ig[n].onmousedown = function(e){
e = window.event
[解决办法]
e;
var w = e.which
[解决办法]
e.button;
if( w == 2){
return false;
}
ig[n].setAttribute('IsMove', 'false');
return Move(ig[n], e);
}
ig[n].onclick = function(){
if(this.getAttribute('IsMove') == 'true'){
return false;
}
}
})(i)
}
</script>
</body>
</html>