jquery将类从标记的th标签添加到TR
我需要动态地添加一个类,该类等于父tr的标签标签的值。。。下面是我的HTML代码jquery将类从标记的th标签添加到TR,jquery,Jquery,我需要动态地添加一个类,该类等于父tr的标签标签的值。。。下面是我的HTML代码 <tr valign="top"> <th scope="row"> <label for="field[85]" id="rahil">File Upload</label> </th> <td style="background:#eee;border:1px solid #ddd"><a href="" target
<tr valign="top">
<th scope="row">
<label for="field[85]" id="rahil">File Upload</label>
</th>
<td style="background:#eee;border:1px solid #ddd"><a href="" target="_blank">Info here</a></td>
</tr>
生成的代码应该类似于:
<tr valign="top" class="field85">
<th scope="row">
<label for="field[85]" id="rahil">File Upload</label>
</th>
<td style="background:#eee;border:1px solid #ddd"><a href="" target="_blank">Info here</a></td>
</tr>
文件上传
基本上,要获取值的标签,将其作为类添加到父tr中,并删除括号[]
有什么想法吗?看起来这个类被添加了,但是有括号,所以只需将它们替换为零:
$("tr th label").each(function () {
var id = $(this).attr("for").replace(/(\[|\])/g,'');
$(this).closest('tr').addClass(id);
});
似乎添加了类,但使用了括号,因此只需将它们替换为零:
$("tr th label").each(function () {
var id = $(this).attr("for").replace(/(\[|\])/g,'');
$(this).closest('tr').addClass(id);
});
您只需添加。替换
var id = $(this).attr("for").replace(/(\[|\])/g,'');
^ ^ = ^
替换方法您只需添加。替换
var id = $(this).attr("for").replace(/(\[|\])/g,'');
^ ^ = ^
替换方法