我有一个元素的网页,当鼠标悬停在元素上时,文本出现在元素内部。 我想要生成“鼠标悬停”/“鼠标”显示文本,即使没有鼠标实际悬停在元素上。 代码,例如:jQuery在没有实际鼠标输入元素的情况下触发mouseenter元素
HTML
<div>
<span id="hover_to_show_text">Hover here to show hidden text</span>
<span id="hidden_text" style="display:none">Hidden text</span>
</div>
JS
$("#hover_to_show_text").mouseenter(function() {
$(#hidden_text).show();
});
$("#hover_to_show_text").mouseleave(function() {
$(#hidden_text).hide();
});
我想产生 “的mouseenter” 这会触发“$( “#hover_to_show_text”).mouseenter (函数(){“在jQuery中,并在那里离开”mouseenter“达N秒。我试过(分开):
$("#hover_to_show_text").hover();
$("#hover_to_show_text").trigger('mouseover');
$("#hover_to_show_text").trigger('mouseenter');
没有工作。有没有办法做到这一点?
谢谢。
不知道我完全理解你的问题。但在你的代码放在jsfiddle后,它似乎触发mouseover和mouseenter成功http://jsfiddle.net/p694huuk/ – EmileKumfa
我不认为你正在做对了你的代码运行良好....你确定你有jQuery在你的项目 – code
在上面的代码中有错别字。和'$(“#hover_to_show_text”)。trigger(“mouseenter”);'应该工作。 – epascarello