onClick() 和鼠标中键的问题 [英] Issue with onClick() and middle button on mouse

查看:14
本文介绍了onClick() 和鼠标中键的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a href="<?=$rowz[0]?>" onClick="countLinks('<?=$row[6]?>','<?=$indexl?>')">[Link <?=$j++?>]</a>

问题是它不适用于 IE 或 firefox 上的中间按钮.实际上,countLinks 使用中间按钮只能用 chrome 调用.

The problem is that it doesn't work with middle button on IE or firefox. In fact, the countLinks using middle button is called only with chrome.

我想我需要一个像 mouseup 事件这样的 Jquery 函数,只是我不知道如何调用该函数,它使用这些参数参数调用 countLinks.

I think I need a Jquery function like mouseup event, just I don't know how call that function, which it calls countLinks with those parameters parameters.

有什么帮助吗?

推荐答案

你是对的.您需要一个 mousedownmouseup 事件来确定实际单击了哪个鼠标按钮.

You're right. You need a mousedown or mouseup event to determine which mouse button was actually clicked.

但首先,您需要摆脱那个内联事件处理程序 onclick 并遵循 unobtrusive javascript 的光辉之路.

But first of all, you need to get rid of that inline-event handler onclick and follow the shining road of unobtrusive javascript.

那你需要给那个锚一个 idclass 标签来识别它(当然你也可以选择用css选择器选择那个锚).假设我们添加了一个名为 myClazzz 的类 :)

Thatfor you need to give that anchor a id or class tag to identify it (Of course you may also choose to select that anchor with a css selector). Lets assume we have added a class with the name myClazzz :)

javascript:

javascript:

$(function(){
    $('.myClazzz').bind('mouseup', function(e){
        switch(e.which){
           case 1:
              alert('Left Mouse button pressed.');
           break;
           case 2:
              alert('Middle Mouse button pressed.');
           break;
           case 3:
              alert('Right Mouse button pressed.');
           break;
           default:
              alert('You have a strange Mouse!');
        }
    });
});

mousedown/mouseup 事件处理程序中的 which 属性将包含一个数字,指示单击了哪个鼠标按钮.

The which property within a mousedown / mouseup event handler will contain a number which indicates which mousebutton was clicked.

这篇关于onClick() 和鼠标中键的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆