Jquery 如何将鼠标悬停在div框上并使其第一个子项出现?
这是我的问题后面的代码 jQueryJquery 如何将鼠标悬停在div框上并使其第一个子项出现?,jquery,html,css,jquery-selectors,css-selectors,Jquery,Html,Css,Jquery Selectors,Css Selectors,这是我的问题后面的代码 jQuery $(document).ready(function(){ $('.dude').hover(function(){ $('div').find(">:first-child").css( "display", "inline" ); }, function() { $('div').find(">:first-child").css( "display", "hidden" ); ); });
$(document).ready(function(){
$('.dude').hover(function(){
$('div').find(">:first-child").css( "display", "inline" );
}, function() {
$('div').find(">:first-child").css( "display", "hidden" );
);
});
CSS
HTML
onetwotree
当我使用类“dude”将鼠标悬停在div框上时,只要用户悬停,我就试图使两个出现,然后它返回到隐藏状态。您可以使用CSS:
.dude > :first-child {
display: none;
}
.dude:hover > :first-child {
display: inline;
}
试试看
尝试
注意:您缺少一个“}”来关闭悬停功能:)当然是首选方式,只需注意IE9之前的IE支持有限:)IE8支持:第一胎。您唯一的错误是
隐藏的应该是无,而中缺少}
)代码>行。
<div class="dude">ONE<div>TWO</div>three</div>
.dude > :first-child {
display: none;
}
.dude:hover > :first-child {
display: inline;
}
$(document).ready(function(){
$('.dude').hover(function(){
$(this).children('div').first().css( "display", "inline" );
}, function() {
$(this).children('div').first().hide();
});
});
$(document).ready(function(){
$('.dude').hover(function(){
$(this).children().eq(0).css( "display", "inline" );
}, function() {
$(this).children().eq(0).hide();
});
});