我有以下html结构:
<ul class="dpt1 yui-dt-ul ui-sortable">
<li class="dpt1 yui-dt-first dpt1 yui-dt-even">
<input class="sort" type="hidden" data-sort="1" data-rule-id="8337" data-ruletype="2" data-dpt="1" data-cid="1511"/>
<a class="CSSprite btn16 ed etib" title="Edit rule" href="#" data-ruletype="2" data-dpt="1" data-cid="1511" data-rule-id="8337">Edit rule</a>
<a class="CSSprite btn16 nuke etib" title="Delete rule" href="#" data-ruletype="2" data-dpt="1" data-cid="1511" data-rule-id="8337">Delete rule</a>
Price New 2010 Dodge Avenger cars at List Price - $300 (Discount: -300) Sort Order:
<input class="sorttextbox" type="text" maxlength="5" data-sort="1" data-rule- id="8337" data-ruletype="2" data-dpt="1" data-cid="1511" value="1"/>
</li>
<li class="dpt1 yui-dt-odd WarnMsg">
<input class="sort" type="hidden" data-sort="2" data-rule-id="9100" data-ruletype="2" data-dpt="1" data-cid="1511"/>
<a class="CSSprite btn16 ed etib" title="Edit rule" href="#" data-ruletype="2" data-dpt="1" data-cid="1511" data-rule-id="9100">Edit rule</a>
<a class="CSSprite btn16 nuke etib" title="Delete rule" href="#" data-ruletype="2" data-dpt="1" data-cid="1511" data-rule-id="9100">Delete rule</a>
Price New 2008 zzTEST Grand Caravan C/V Gas V6 3.3L/202 cars at List Price Sort Order:
<input class="sorttextbox" type="text" maxlength="5" data-sort="2" data-rule- id="9100" data-ruletype="2" data-dpt="1" data-cid="1511" value="2"/>
</li>
</ul>
有些人可以建议我如何通过子输入标签数据排序值来获取li元素?
答案 0 :(得分:1)
试试这个:
$("input[data-sort='1']").parent();
答案 1 :(得分:0)
如果您希望<li>
元素的输入子元素为data-sort="1"
,那么您可以这样做:
$("ul li input[data-sort='1']").closest("li");
答案 2 :(得分:0)
您可以通过子输入标记data-sort
属性值轻松获取父li元素:
var attributevalue = "1"; //-- Enter your desired `data-sort` value
$("input[data-sort='" + attributevalue + "']").parent();