Select table 行按 ID 开头和名称
Select table row by id begins with and name
看起来这么简单的事情应该很简单,但显然我不明白...
我需要遍历每个 table 行 (.each
),ID 以 "pc-" ("tr[id^='pc-']
) 开头,并且有一个特定的名称 ([name='someValue']
).我目前拥有的:
$("tr[id^='pc-'] name=" + $(this).attr("appliesto") + " ").each(function ()...
目前为止我看到的例子是这样的:
$("#someID[name='somevalue']".somethingsomethingsomething...
但显然它不起作用....我知道问题出在选择器之间的 space 但在这种情况下您将如何链接选择器?
我需要什么来代替?
你很接近:
$("tr[id^='pc-'][name=" + $(this).attr("appliesto") + "]").each(function ()...
或者更清楚一点:
var name = $(this).attr("appliesto");
$("tr[id^='pc-'][name=" + name + "]").each(function ()...
真的,如果你想要的只是 appliesto
属性值,你可以省略 jQuery:
var name = this.getAttribute("appliesto");
$("tr[id^='pc-'][name=" + name + "]").each(function ()...
无需创建新的 jQuery 对象,只需调用 this.getAttribute(...)
即可。
看起来这么简单的事情应该很简单,但显然我不明白...
我需要遍历每个 table 行 (.each
),ID 以 "pc-" ("tr[id^='pc-']
) 开头,并且有一个特定的名称 ([name='someValue']
).我目前拥有的:
$("tr[id^='pc-'] name=" + $(this).attr("appliesto") + " ").each(function ()...
目前为止我看到的例子是这样的:
$("#someID[name='somevalue']".somethingsomethingsomething...
但显然它不起作用....我知道问题出在选择器之间的 space 但在这种情况下您将如何链接选择器?
我需要什么来代替?
你很接近:
$("tr[id^='pc-'][name=" + $(this).attr("appliesto") + "]").each(function ()...
或者更清楚一点:
var name = $(this).attr("appliesto");
$("tr[id^='pc-'][name=" + name + "]").each(function ()...
真的,如果你想要的只是 appliesto
属性值,你可以省略 jQuery:
var name = this.getAttribute("appliesto");
$("tr[id^='pc-'][name=" + name + "]").each(function ()...
无需创建新的 jQuery 对象,只需调用 this.getAttribute(...)
即可。