我希望鼠标悬停事件发生在css选择器上,而鼠标光标在不同的元素上。我需要通过运行js的Google tag Manager中的自定义标记来设置它。我的想法是:
(function() {
document.getElementById("atcclick").mouseover();
})();当我使用.click的时候,在#atcclick上的一个点击被识别出来了,效果非常好!但是对于.mouseover,不能识别鼠标悬停事件。你知道我做错了什么吗?
发布于 2021-05-20 06:54:51
多亏了epascarello我得到了它,这是工作的:
(function() {
document.getElementById('atcclick').dispatchEvent(new MouseEvent('mouseover', { 'view': window, 'bubbles': true, 'cancelable': true }));
})();发布于 2021-05-18 19:52:54
You should use .onmouseover() method instead of .mouseover()。
做一些像这样的事情-
(function() {
document.getElementById("atcclick").onmouseover = function(){ console.log('on mouseover event')};
})();<p id="atcclick">This is demo text</p>
https://stackoverflow.com/questions/67585303
复制相似问题