我需要获取TR标签的“pp”属性值 其TD标签具有“KK”属性。
<TR pp="I hava to read this.">
<TD kk > </TD>
</TR>
<TR pp="Don't want this...">
<TD > </TD>
</TR>
如何使用1行jQuery命令执行此操作?
答案 0 :(得分:1)
尝试
var elem = $("tr td").filter(function(i, el) {
return $(el).attr("kk") !== undefined
}).parent("tr").attr("pp");
var elem = $("tr td").filter(function(i, el) {
return $(el).attr("kk") !== undefined
}).parent("tr").attr("pp");
console.log(elem)
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<TR pp="I hava to read this.">
<TD kk> </TD>
</TR>
<TR pp="Don't want this...">
<TD> </TD>
</TR>
</table>
&#13;
答案 1 :(得分:0)
<TR pp="I hava to read this.">
<TD data-test="kk" > </TD>
</TR>
<TR pp="Don't want this...">
<TD > </TD>
</TR>
答案 2 :(得分:0)
var pp_text = $("td[kk]").parent().attr("pp");