jquery访问动态类选择器
给定以下html呈现jquery访问动态类选择器,jquery,Jquery,给定以下html呈现 <fieldset id="fld_Rye"> <legend>7 Main St.</legend> <div> <table> <tr> <th class="wideCol"><b><i>Service Description</i></b></th> <th c
<fieldset id="fld_Rye">
<legend>7 Main St.</legend>
<div>
<table>
<tr>
<th class="wideCol"><b><i>Service Description</i></b></th>
<th class="wideCol"><b><i>Service Name</i></b></th>
<th class="normalPlusWidth"><b><i>Contact Name</i></b></th>
</tr>
<ItemTemplate>
<tr class="">
<td class="servDesc"> <b>Plumbing Services</b></td>
<td class="servName"> <b>Flynnsters's Plumbing</b></td>
<td class="servContact"> <b>Jim Flynnster</b></td>
</tr>
</ItemTemplate>
要使用
servDesc
类获取所有td
,请尝试以下操作
$("td.servDesc").each(function () {
alert("found one");
servDescCols.push(this.width());
});
如果您想针对任何元素并获得td,请使用此
“table1”是基本元素的id
$("#table1").find("td.servDesc").each(function () {
alert("found one");
servDescCols.push(this.width());
});
是的,我知道这是可行的,但是这个页面可能有不止一个表,我希望选择器中有更多的层次结构,即定义div和sub td.servDesc而不是任何td.servDesc标记,当它们在页面上是多个时,它也只会找到一个确实有效,但是有17个td标记与该选择器一起,并且是唯一找到的一个,或者更好的是,推送功能不起作用,脚本在第一次循环后退出。我还将此更改为$(此)
$("#table1").find("td.servDesc").each(function () {
alert("found one");
servDescCols.push(this.width());
});