如何获取标签的属性值,该标签具有" KK"属性与jQuery?

时间:2014-11-06 00:46:30

标签: jquery attributes

我需要获取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命令执行此操作?

3 个答案:

答案 0 :(得分:1)

尝试

var elem = $("tr td").filter(function(i, el) {
  return $(el).attr("kk") !== undefined
}).parent("tr").attr("pp");

&#13;
&#13;
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;
&#13;
&#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>

var td_you_want = $('td')。data('test');

答案 2 :(得分:0)

var pp_text = $("td[kk]").parent().attr("pp");