Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.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
Jquery 悬停时选择元素_Jquery - Fatal编程技术网

Jquery 悬停时选择元素

Jquery 悬停时选择元素,jquery,Jquery,我需要在悬停效果上分配元素,但我遇到了一个问题: $('html *') .on('mouseover', function(){ $(this).addClass('hint-mode_show-block'); }) .on('mouseout', function(){ $(this).removeClass('hint-mode_show-block'); }) 虽然我需要选择最新级别,但这段代码分配所有父元素 我需要获得firebug或其他浏览器检查器的效果,才能停止

我需要在悬停效果上分配元素,但我遇到了一个问题:

$('html *')
.on('mouseover', function(){
    $(this).addClass('hint-mode_show-block');
})
.on('mouseout', function(){
    $(this).removeClass('hint-mode_show-block');
})
虽然我需要选择最新级别,但这段代码分配所有父元素


我需要获得firebug或其他浏览器检查器的效果,才能停止冒泡。您需要使用
事件。stopPropagation()

这样使用:

$('*')
.on('mouseover', function(e){
e.preventDefault();    
$(this).addClass('hint-mode_show-block');
})
.on('mouseout', function(e){
e.preventDefault();    
$(this).removeClass('hint-mode_show-block');
})
这样做:

$('*')
.on('mouseover', function(e){
e.preventDefault();    
$(this).addClass('hint-mode_show-block');
})
.on('mouseout', function(e){
e.preventDefault();    
$(this).removeClass('hint-mode_show-block');
})
假设您的html看起来像

<div id="big">
    <p id="big">Hello Big</p>
<div>
    <p id="inner">Inner</p>
    </div>
</div>

工作小提琴:

您的选择器将在任何元素上熄灭并弹出气泡,因为如果您将鼠标悬停在子元素上,您也将鼠标悬停在父元素上。
$("html *").hover(function(e){
    e.stopPropagation();
   $(e.target).addClass('hint-mode_show-block');
},function(e){
e.stopPropagation();
    $(e.target).removeClass('hint-mode_show-block');
});