1.禁用鼠标左右键
function click(event){ event = event||window.event;//考虑兼容性 if(event.button == 2){ //单击鼠标为右键 alert("禁止使用鼠标右键"); } else{ alert("禁止使用鼠标左键"); } } document.onmousedown=click; //绑定事件
2.鼠标移动时的坐标
window.onload=function(){ var mydiv = document.createElement("div"); mydiv.setAttribute("id","hint"); mydiv.style.position="absolute"; document.body.appendChild(mydiv); document.addEventListener("mousemove",function(e){ var myhint = document.getElementById("hint"); myhint.style.left= e.clientX+"px"; myhint.style.top= e.clientY+"px"; myhint.innerHTML=e.clientX+" :"+e.clientY; }); }
3.禁止鼠标滚动(失败)
document.onmousewheel = function(){return false;} function document.onmousewheel(){ return false; }
4.鼠标直接直接跳转百度首页
function newPage(event){ event = event||window.event; if(event.button == 2){ location.replace("http://www.baidu.com"); } } document.onmousedown=newPage;
IE8运行失败
5.鼠标放到图片上显示另一张图片
<script type="text/javascript"> function change(e){ e.src="2.png"; } </script> <img onmousedown="change(this)" src="1.png"/>