我有一个脚本:
if (el.tags.includes(selectedTag)) {
const itemsContent = document.createElement('div');
itemsContent.className = 'items-content';
const h2 = document.createElement('h2');
h2.className = 'project-title';
h2.innerHTML = el.title;
div.appendChild(h2);
main.appendChild(div);
}
而且我希望能够在“ itemsContent” div中添加鼠标悬停
生成类似
的内容:<div onmouseover="onProjectHover(...)" class="items-content"> My content</div>
谢谢;)
答案 0 :(得分:1)
使用
itemsContent.addEventListener("mouseenter", function (event)){
// your event handler code goes here
})
引用https://developer.mozilla.org/en-US/docs/Web/API/Element/mouseover_event