如:
<div class="mostOut">
<div class="a">
<h3 class="b"></h3>
<div class="d"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我怎样才能同时将css风格应用于孩子们"moustOut".Eg:
与一个click event.the css('opacity',1)可以适用于"a","b","d"在同一时间.或者,排除"b".
少一点代码
$('.mostOut').click(function()
{
$(this).children("*").css('opacity', 1);
});
Run Code Online (Sandbox Code Playgroud)
并排除".b"
$('.mostOut').click(function()
{
$(this).children("*").not(".b").css('opacity', 1);
});
Run Code Online (Sandbox Code Playgroud)
或者,如果它不是导致隐藏/无的不透明度
$('.mostOut').click(function()
{
$(this).children("*").show();
});
Run Code Online (Sandbox Code Playgroud)
这可能是一个肮脏的解决方案,但它应该有效:
$('.mostOut').click(function()
{
$(this).find('*').each(function()
{
$(this).css('opacity', 1);
});
});
Run Code Online (Sandbox Code Playgroud)
要排除除b元素之外的所有元素,请尝试以下操作:
$('.mostOut').click(function()
{
$(this).find('*').not('.b').each(function()
{
$(this).css('opacity', 1);
});
});
Run Code Online (Sandbox Code Playgroud)
尝试一下代码,因为我只是凭空想出这个代码,所以我不保证它会起作用。
祝你好运!