Jag*_*agd 1 javascript jquery dom
我有以下HTML:
<div id="myDiv">
<table id="tbl0">
<tr id="tr0" style="display: none;">
<td>
<label id="lbl0"></label>
</td>
</tr>
<tr id="tr1" style="display: none;">
<td>
<label id="lbl1"></label>
</td>
</tr>
<tr id="tr2" style="display: none;">
<td>
<label id="lbl2"></label>
</td>
</tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
以下jquery将行设置为可见,并使用一些文本更新(但失败)label标签.
var myStr = $(this).text();
var myArr = myStr.split(',');
$.each(myArr, function (i) {
// This part works just fine
var tr = $('#myDiv').find("#tr" + i);
tr.css('display', 'inline');
// The label is found, but I can't get jquery to update the text of
// ...it no matter what I try
var lbl = tr.find("lbl" + i);
lbl.val('hello world'); // doesn't work
lbl.text('hello world'); // doesn't work
lbl.html('hello world'); // doesn't work
});
Run Code Online (Sandbox Code Playgroud)
那么我在这里做错了什么?
试试这个...
var lbl = tr.find("#lbl" + i);
Run Code Online (Sandbox Code Playgroud)
您正在尝试选择一个<lbl1/>显然不存在的标记
用于#指定要搜索的ID.
| 归档时间: |
|
| 查看次数: |
2240 次 |
| 最近记录: |