Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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触发jQuery事件_Javascript_Jquery_Events_Event Handling_Jquery Events - Fatal编程技术网

使用普通Javascript触发jQuery事件

使用普通Javascript触发jQuery事件,javascript,jquery,events,event-handling,jquery-events,Javascript,Jquery,Events,Event Handling,Jquery Events,我知道不可能用普通Javascript处理jQuery事件,但是可以用普通Javascript触发jQuery事件吗 比如: $('body').trigger('myevent', myvar); 这是你想要的吗 document.body.addEventListener('event', myFunction); // add a listener for the event function myFunction(event) { // this function will be c

我知道不可能用普通Javascript处理jQuery事件,但是可以用普通Javascript触发jQuery事件吗

比如:

$('body').trigger('myevent', myvar);
这是你想要的吗

document.body.addEventListener('event', myFunction); // add a listener for the event

function myFunction(event) { // this function will be called when the event happens
   // handle event
}

是的,因为JQuery只是一个JS库:

这个

相当于:

elem.dispatchEvent(myevent);
问题是:为什么需要混合使用vanilla JS和JQuery?

不,OP想要触发事件,而不是绑定事件
elem.dispatchEvent(myevent);