简体   繁体   English

如何从 jQuery 触发鼠标移动事件

[英]How to trigger a mouse move event from jQuery

I'm trying to manually trigger a mousemove event with jQuery.我正在尝试使用 jQuery 手动触发mousemove事件。 Demo in this fiddle http://jsfiddle.net/qJJQW/演示在这个小提琴http://jsfiddle.net/qJJQW/

From other similar posts on Stack Overflow it seems that this should work.从 Stack Overflow 上的其他类似帖子来看,这似乎应该有效。 Why isn't it?为什么不是?

Use jQuery to bind the mousemove event:使用 jQuery 绑定 mousemove 事件:

$(function () {
   $("#test").on("mousemove", youCantHandleTheFunc);

    $('#button').click(function () {
        $('#test').trigger('mousemove', {type:'custom mouse move'});
    });
});

function youCantHandleTheFunc (e,customE) {
    if (customE != undefined) {
         e = customE;   
    }
    $('#result').html(e.type);
}

Your updated fiddle.你更新的小提琴。

jQuery's trigger() only triggers event handlers set with jQuery ? jQuery 的trigger()只触发用 jQuery 设置的事件处理程序?

$(function(){
    $('#test').on('mousemove', youCantHandleTheFunc); 

    $('#button').click(function(){
        $('#test').trigger('mousemove',{type:'custom mouse move'});
    });
});

function youCantHandleTheFunc(e,customE){
    if (customE!=undefined){
         e=customE;   
    }
    $('#result').html(e.type);
}

FIDDLE小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM