首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

在页面中确定点击鼠标的上下键

2012-11-04 
在页面中确定点击鼠标的左右键当页面中点击带有链接的图片时,要求只在点击鼠标左键的时候才发生页面的跳转

在页面中确定点击鼠标的左右键

当页面中点击带有链接的图片时,要求只在点击鼠标左键的时候才发生页面的跳转,解决办法:

????? 可以在图片的那个地方添加onmousedown事件,如:onmousedown="turn(event)"

<script type="text/javascript">function turn(event){var event = (event)?event:window.event;if(event.button == 1 || (!document.all&&event.button == 0)){return window.location = "www.sina.com.cn";}}</script>

在IE中event作为window对象的一个属性可以直接使用,但是在Firefox中却使用了W3C的模型,它是通过传参的方法来传播事件的,也就是说你需要为你的函数提供一个事件响应的接口,如上述函数中的event

IE中:event.button == 1 左键? event.button == 2 右键

Firefox中:event.button == 0 左键 event.button==1 右键

TT中: event.button = 1 左键 ?? event.button = 0? 右键
Maxthon3中:event.button = 0 左键?????? event.button = 2 右键
Maxthon2中:event.button = 1 左键?????? event.button = 0 右键

热点排行