【问题标题】:mousemove handler not called with JQuery .mousemove() or .trigger未使用 JQuery .mousemove() 或 .trigger 调用 mousemove 处理程序
【发布时间】:2013-09-18 07:43:53
【问题描述】:

当使用 addEventListener() 添加 mousemove 处理程序时,该处理程序将永远不会被调用 通过 $(xx).mousemove() 或 $(xx).trigger(e) 使用 JQuery 模拟事件,其中 e 是 jquery 事件。 但是在纯 JS dispatchEvent 模拟事件时可以调用监听器。 任何人都可以解释?我的环境是 Mac + chrome。

代码在这里http://jsfiddle.net/eepaul/r8W2h/

<body>
    <ul id="id_ul">
      <li id="a">oooo</li>
      <li id="b">jjjj</li>
    </ul>
    <p id="console"></p>
</body>

js

var liA = $("li#a")[0];
var ul = $("ul")[0];
var p = $("p#console")[0];
ul.addEventListener("mousemove", function(e) {
    $(p).text($(p).text() + "mousemove triggered\n");       
}, false);

var event = $.Event("mousemove", {
    canBubble:true, 
    cancelable: true,
    view:liA.ownerDocument.defaultView,
    detail: 1,
    screenX:0, //The coordinates within the entire page
    screenY: 0,
    clientX: 0, //The coordinates within the viewport
    clientY: 0,
    ctrlKey:false,
    altKey:false,
    shiftKey: false,
    metaKey:false, //I *think* 'meta' is 'Cmd/Apple' on Mac, and 'Windows key' on Win. Not sure, though!
    button: 0, //0 = left, 1 = middle, 2 = right
    relatedTarget:null
 });

//neither of the following 2 ways can trigger the handler   
window.setTimeout(function() {
    $(liA).trigger(event);}, 1000);

window.setTimeout(function() {
    $(liA).mousemove();}, 1000);

【问题讨论】:

    标签: javascript


    【解决方案1】:

    嗯。似乎是 jquery 中的一个已知问题。 http://bugs.jquery.com/ticket/4314

    【讨论】:

      猜你喜欢
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多