如何使用jQuery选择此元素:
如何使用jQuery、vanilla JS或CSS选择以下范围如何使用jQuery选择此元素:,jquery,css,Jquery,Css,如何使用jQuery、vanilla JS或CSS选择以下范围 <span style="vertical-align:bottom"> Jquery: 如前所述,您可以使用$span[style^=vertical align] 如果你只想瞄准第一个或第二个等,你可以 加: CSS 3 同样的想法: span[style^=vertical-align] { some properties } 两种选择: $('span[style*="vertical-align:
<span style="vertical-align:bottom">
Jquery:
如前所述,您可以使用$span[style^=vertical align]
如果你只想瞄准第一个或第二个等,你可以
加:
CSS 3
同样的想法:
span[style^=vertical-align] {
some properties
}
两种选择:
$('span[style*="vertical-align:bottom"]');
[style*=vertical align:bottom]查看元素的style属性是否包含以字符串vertical align:bottom开头的字符串,该字符串比简单地使用以*style^=vertical align:bottom开头的选择器更可靠
尽管这取决于是否存在空白,但请注意,在上面的演示中,它无法选择第一个元素。或者,您可以使用以下选项:
$('span[style]').filter(function(){
return this.style.verticalAlign === 'bottom';
});
以上演示使用以下HTML:
<span style="vertical-align: bottom">This has <code>style="vertical-align: bottom"</code></span>
<span style="vertical-align:bottom">This has <code>style="vertical-align:bottom"</code></span>
<span>This span has no style attribute at all</span>
<span style="color:#f00;vertical-align:bottom">This has <code>style="color:#f00;vertical-align: bottom"</code></span>
参考资料:
.
.
$span[style^=vertical align]只是一个小提示:attribute^=property是一个CSS 3选择器
$('span[style*="vertical-align:bottom"]');
$('span[style]').filter(function(){
return this.style.verticalAlign === 'bottom';
});
<span style="vertical-align: bottom">This has <code>style="vertical-align: bottom"</code></span>
<span style="vertical-align:bottom">This has <code>style="vertical-align:bottom"</code></span>
<span>This span has no style attribute at all</span>
<span style="color:#f00;vertical-align:bottom">This has <code>style="color:#f00;vertical-align: bottom"</code></span>