我想选择所有没有id等于x的HTML
<span>
元素并将它们隐藏。这个有可能吗?我认为你必须使用:not
选择器,但是我无法理解:
$('span:not(#x)').attr('style', "display: none;");
有什么想法吗?谢谢 :).
<span>
元素并将它们隐藏。这个有可能吗?我认为你必须使用:not
选择器,但是我无法理解:
$('span:not(#x)').attr('style', "display: none;");
有什么想法吗?谢谢 :).
$('span[ID!="x"]').attr('style', "display: none;");
将所有没有id为x的元素的style属性设置为none。
希望这能帮到你
$('span:not(#x)').attr('style', "display: none;");
$('span[id!="x"]').attr('style', "display: none;");
$('span').filter(':not(#x)').attr('style', "display: none;");
$('span[id!="x"]').attr('style', "display: none;");
。$('span[id!="x"]').attr('style', "display: none;");
$('span:not(#x)').hide()
。因为将样式属性设置为display: none;
会替换掉所有现有的内联样式,而hide()
只会添加display: none;
。要显示元素,只需调用.show()
即可,它只会移除display: none;
样式。 - drovani