0
我有一个只有几行的表格。每行都有标题,数据和隐藏字段。数据列可以具有文本或textarea。访问不同类型的元素
<table id="knowledgeTreeTable" class="custom">
<tbody>
....................
<tr>
<th class="">What is the name of the party?</th>
<td class="">
<textarea id="ktField_7" class="ktEdit" type="text"></textarea>
</td>
<input id="ktField_7H" type="hidden" value="Unique contested">
</tr>
<tr>
<th class="">What is the name of the opposing party?</th>
<td class="">
<input id="ktField_8" class="ktEdit" type="text" style="width: 97%;">
</td>
<input id="ktField_8H" type="hidden" value="Query">
</tr>
......................
</tbody>
</table>
我能读头和隐藏字段,但不知道如何读的数据列,因为它可以有两种不同类型的元素的内容。
$("#knowledgeTreeTable tr").each(function() {
alert($('th', this).text());//OK
//alert($('td > [input, textarea]', this).val()); // This is not OK.
alert($('input', this).val());//OK
});
'警报($(“输入,文本区域”,这一点).VAL() );' – Moob 2014-09-04 20:48:18
您的HTML无效:只有'
回答
就像你在一个CSS选择器,寻找都:
虽然由于您使用的两种同一类,我会倾向于使用:
来源
2014-09-04 20:46:43
你不能像
相反组选择,使用
来源
2014-09-04 20:45:54 Oriol
每当你想在这样的循环来访问的子元素,你需要建立什么样的共同每个元素之间的因素是。在这种情况下,它们是具有不同名称的不同标签,但它们都具有ktEdit类,并且都具有
type="text"
(我不相信它实际上适用于textareas)。在这种情况下,公共变量是类名,所以你可以使用它作为你的选择器。只要你正确地定位你的父母循环,如果使用在整个页面上的其他元素类都不会有问题:
来源
2014-09-04 21:05:53
相关问题