【发布时间】:2013-07-03 15:21:52
【问题描述】:
我有一段带有粗体字的段落
<p style="class1"><b>Some text</b> some other text</p>
以及用于mouseenter 和class1 元素的mouseout 事件的jQuery 侦听器
$('class1').mouseenter(function(){
$(this).addClass("highlight");
});
$('class1').mouseout(function(){
$(this).removeClass("highlight");
});
highlight 类是一种模拟经典 HTML 选择的样式。
.highlight{
background-color: blue;
color: white !important
}
(我没有使用 style1:hover 因为我想以编程方式模拟箭头选择,但这现在并不重要)
所以,我有一些这样的段落:
一些文字一些其他文字
一些文字一些其他文字
一些文字一些其他文字
现在,我的问题是当鼠标光标从粗体文本移动到普通文本(或反之亦然)时,mouseout 事件触发,失去我的假选择但留在同一段落中。如何避免这种行为?
【问题讨论】:
标签: jquery mouseenter mouseout paragraph bold