【发布时间】:2012-04-14 16:12:40
【问题描述】:
我正在尝试循环浏览一些表格行。简化的行如下:
<table>
<tr id="ucf48">
<td class="ucf_text">
<input name="ucf_t48" value="Ann becomes very involved in the text she is reading." type="text">
</td>
</tr>
<tr id="ucf351">
<td class="ucf_text">
<input name="ucf_t351" value="Ann is a fast and confident reader." type="text">
</td>
</tr>
</table>
我正在使用此代码循环:
$('#ucf tr').each(function(i,obj){
var cn=$(this).attr('id').substr(3);
var t=$(this +'.ucf_text input').val();
console.log("Row "+i);
console.log("Cnum: "+cn);
console.log(t);
});
控制台输出为:
Row 0
Cnum: 48
Ann becomes very involved in the text she is reading.
Row 1
Cnum: 351
Ann becomes very involved in the text she is reading.
现在在有人激怒我之前,我知道我可以通过使用“名称”引用我想要的数据来以另一种方式做到这一点。但是,为什么我的 cnum 变量跟随 'this' 而 t 变量却没有?
谢谢。
【问题讨论】:
-
谢谢大家。我今天又学到了一些东西:)