mmi*_*ins 9 html javascript jquery
如何选择具有特定样式属性?
<div style="width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;">
Run Code Online (Sandbox Code Playgroud)
我尝试着:
$("div[style='width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;']);
Run Code Online (Sandbox Code Playgroud)
但没有任何东西被选中
Orb*_*ing 14
你的例子适用于我,至少在Chrome中,一旦我纠正了缺失的错误"在行尾.
$("div[style='width: 420px; text-align: left; margin-top: 10px; margin-bottom: 10px;']");
Run Code Online (Sandbox Code Playgroud)
Fré*_*idi 10
据我所知,使用jQuery选择器无法做到这一点,但您可以使用filter()方法:
$("div").filter(function() {
var $this = $(this);
return $this.css("width") == "420px"
&& $this.css("text-align") == "left"
&& $this.css("margin-top") == "10px"
&& $this.css("margin-bottom") == "10px";
});
Run Code Online (Sandbox Code Playgroud)