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

How to trigger a mouse move event from jQuery

本文关键字:鼠标 移动 事件 jQuery      更新时间:2023-09-26

我正在尝试使用 jQuery 手动触发mousemove事件。演示这个小提琴 http://jsfiddle.net/qJJQW/

从堆栈溢出上的其他类似帖子来看,这似乎应该有效。为什么不是呢?

使用 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);
}

你更新的小提琴。

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);
}

小提琴