Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 听Raphael.js右键单击svg元素_Javascript_Svg_Raphael - Fatal编程技术网

Javascript 听Raphael.js右键单击svg元素

Javascript 听Raphael.js右键单击svg元素,javascript,svg,raphael,Javascript,Svg,Raphael,当用户右键单击使用Rapahel.js创建的元素时,我需要做出响应。我读到您应该附加一个click事件处理程序,然后决定用户单击了哪个鼠标按钮。我不能让它工作 <!DOCTYPE html> <html> <head> <script src="http://raphaeljs.com/raphael.js"></script> <script> window.onload = function() {

当用户右键单击使用Rapahel.js创建的元素时,我需要做出响应。我读到您应该附加一个click事件处理程序,然后决定用户单击了哪个鼠标按钮。我不能让它工作

<!DOCTYPE html>
<html>
<head>
<script src="http://raphaeljs.com/raphael.js"></script>
<script>
    window.onload = function() {
       var r = Raphael('demo', 640, 480);
       r.rect(10, 10, 400, 400).attr({fill: 'red'}).click(function(){
          alert('test');
       });;
    };
</script>
</head>
<body>
    <div id="demo"></div>
</body>
</html>
但也请阅读以下内容:

是的,这也有效,但只适用于jQuery,而且最好不要使用.node, 由于Raphael有时会重新创建节点,因此会丢失事件处理程序


您可以使用
mousedown
并测试
e.which
。这适用于FF和Chrome:

var r = Raphael('demo', 640, 480);
r.rect(10, 10, 400, 400).attr({fill: 'red'}).mousedown(function(e){
    if (e.which == 3)
        alert("hi")
});
对于跨浏览器解决方案,您可能还需要查看
e.button


谢谢。当你了解他们时,答案似乎很简单:)
var r = Raphael('demo', 640, 480);
r.rect(10, 10, 400, 400).attr({fill: 'red'}).mousedown(function(e){
    if (e.which == 3)
        alert("hi")
});