问题描述
我有一个样式为text-decoration-line
的CSS类,以及一个使用此类的HTML元素.
I have a CSS class that has style text-decoration-line
, and a HTML element that uses this class.
我希望能够使用jQuery选择器通过text-decoration-line
样式而不是通过元素上的CSS类来获取元素.像这样:
I want to be able to use a jQuery selector to get the element by the text-decoration-line
style, not by the CSS class on the element. Something like:
$("span[style*='text-decoration-line']")
如果我尝试这样做,jQuery将无法识别该类所继承的样式.如果我在元素上明确设置了样式,它就可以工作.
If I try to do that, jQuery doesn't recognize the style inherited by the class. If I explicitly set the style on the element, it works.
JSFiddle: https://jsfiddle.net/akvcwe6t/1/
JSFiddle: https://jsfiddle.net/akvcwe6t/1/
我可以使用jQuery或XPath,两者都可以.
I could use jQuery or XPath, either of them is fine.
推荐答案
您将需要遍历每个元素并检查其计算样式.
You would need to loop through every element and check its computed style.
$("span").each(function(){
if($(this).css('text-decoration-line')!='') {
// do something
}
});
这篇关于使用有效样式(使用从CSS类继承的样式,未在元素上显式)的jQuery查找HTML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!