使用j查询查找下一个td元素
Finding the next td element using j query?
如何使用jquery找到下一个td元素。我试图将文本或div附加到特定tr中的td元素。我的tr是一个服务器端控件,标签runat=server这是我的查询,它不工作
var cssdisable= function testcss(rowid) {
if ($('#testcss').width() != 3) {
var id = $(rowid).find('td');
id.append('The following is not valid');
}
}
这就是我在点击事件
中调用函数的方式 cssdisable('<%=tr_myrow.ClientID %>');
它不做任何事情,也不给出任何错误。我试图在行id旁边的td元素后添加文本。
有什么想法吗
是HTML有一个名为tr_myrow的行
<table id="tblstudysub_animal" class="bond_qbs_table" width="100%">
<tr>
<td valign="top">
<h3>
Select the study subject.<span class="red">*</span></h3>
<fieldset>
<legend class="hide">Select the study subject.</legend>
<table id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj" border="0">
<tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_0" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_studysubj" value="Humans" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_0">Humans</label></td>
</tr><tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_1" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_studysubj" value="Non-Human primates" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_1">Non-Human primates</label></td>
</tr><tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_2" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_studysubj" value="Rodents" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_2">Rodents</label></td>
</tr><tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_3" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_studysubj" value="Others" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_studysubj_3">Others</label></td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_tr_myrow">
<td valign="top">
<div id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_studysub_popul">
<h3>
Select your study subject.<span class="red">*</span></h3>
<fieldset>
<legend class="hide">Select your study subject.</legend>
<table id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_study_popul" border="0">
<tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_study_popul_0" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_study_popul" value="Individuals" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_study_popul_0">Individuals</label></td>
</tr><tr>
<td><input id="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_study_popul_1" type="radio" name="ctl00$m$g_c09fd465_0ae4_479b_8fc6_21a7de645003$ctl00$rdb_study_popul" value="Population" /><label for="ctl00_m_g_c09fd465_0ae4_479b_8fc6_21a7de645003_ctl00_rdb_study_popul_1">Population</label></td>
</tr>
</table>
<div id="testcss">
</div>
我正在尝试将该文本添加到该行的td…
一个问题是,您正试图通过其id查询td
,但没有在选择器开始时使用#
.
try cssdisable('#<%=tr_myrow.ClientID %>');
还为了坚持tr
的td
子元素使用.children()
而不是.find('td')
(将找到所有后代td
元素)
var cssdisable = function testcss(rowid) {
if ($('#testcss').width() != 3) {
var id = $(rowid).children().first();
id.append('The following is not valid');
}
}
在http://jsfiddle.net/D4z9b/(使用您的示例HTML)演示
在表构建阶段为<td>..</td>
元素提供有意义的id(如果不构建它,只需在使用单独调用开始任何处理之前分配它们),然后生成id。像tableName + '_' + row + '_'
这样的东西可能会很好。
相关文章:
- 如何在td元素中添加监听器
- 使用querySelector()获取最后一个td元素
- 使用 Jquery 选择一个 td 元素
- 将图像附加到没有 id 或值的 td 元素
- td元素中带有传递参数的Javascript函数
- 事件点击不在td元素中的多个锚点标记上处理同一个类
- 浏览器中的javascript和td元素事件属性
- 正在获取循环中td元素的tr id
- 正在查找表行中的td元素位置
- 无法动态设置表的 td 元素的值
- td 元素上的 OnClick 函数返回第一列值和标头值
- JQuery 正在添加一个类,但不会从多个 td 元素中删除它
- 使用 javascript 动态添加到 td 元素的 Onclick 不起作用
- 在 jQuery 中更改 TD 元素
- Javascript.使用鼠标悬停事件更改数组中 td 元素的背景颜色
- 使用 JavaScript 移动 html td 元素
- 如何将每个 td 元素的高度设置为其宽度
- 单击时获取TR的所有TD元素
- 使用 jquery find('.classname') 无法定位 TD 元素
- 无法在表的悬停td元素上显示Popover