我遇到过 jQuery 的这一点,但我无法理解 xPath (?) 在这种情况下的含义:
var all_line_height = $(this).find("*[style*='line-height']");
我以前没见过这个,它是在寻找一个在 style 属性中包含 line-height 的元素吗?
我做了一个小测试,但没有成功。
最佳答案
那不是 XPath。它是一个选择器,它从当前选定的元素 (this
) 中选择 style 属性包含 line-height
的任何元素。
$(this) // selects the current element
.find(...) // Select all elements which match the selector:
*[style*='line-height'] // Any element (*),
// whose style attribute ([style])
// contains "line-height" (*='line-height')
可以按如下方式实现:
// HTML:
// <div id="test">
// <a style="line-height:10px;color:red;">...
$("#test").click(function(){
// this points to <div id="test">
var all_line_height = $(this).find("*[style*='line-height']");
alert(all_line_height.length); //Alerts 1
})
关于javascript - 这个 xPath 试图捕获什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8456102/