jQuery - 从表中提取单元格数据
当用户单击表行末尾的按钮时,我需要一些帮助从表中提取单元格数据。该表是通过 Ajax 技术生成的。我不确定这在访问表的元素时是否会产生影响。
<script type='text/javascript' src='jquery.js'></script>
<p>** click me **</p>
<br/>
<div id="placeHolder">some text goes here!</p>
<script>
$("p").click(function () {
$.ajax({
url: "status_2.html",
cache: false,
success: fnSuccess
}
);
});
function fnSuccess(msg)
{
$('div#placeHolder').html(msg);
}
function selectEditActivity(pass_id){
var row = $('#'+pass_id);
var seq = row.attr('seq');
// here I would like to pull the value of the date from the selected row
// but I just can't get syntax right. I get a null value on alert
var from_date = $('td', row).eq(0).html();
alert(from_date);
}
</script>
这是读取的 html 代码(文件:status_2.html)
<span id="status2">
<span id="response" class="response"></span>
<table class="tableBorder">
<tr >
<th class="align_left">Date</th>
</tr><tr>
<tr seq="1" class="row_theme2" id="id3014201105191"></tr>
<tr><td>20090519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105191');" href="#">EDIT</a></td>
</tr>
<tr seq="2" class="row_theme2" id="id3014201105192"></tr>
<tr><td>20100519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105192');" href="#">EDIT</a></td>
</tr>
<tr seq="3" class="row_theme2" id="id3014201105193"></tr>
<tr><td>20110519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105193');" href="#">EDIT</a></td>
</tr>
</tbody></table>
I need some help pulling cell data from table when a user clicks the an button at the end of the table row. The table is generated via Ajax technique. I'm not sure if this makes a difference when accessing elements of the table.
<script type='text/javascript' src='jquery.js'></script>
<p>** click me **</p>
<br/>
<div id="placeHolder">some text goes here!</p>
<script>
$("p").click(function () {
$.ajax({
url: "status_2.html",
cache: false,
success: fnSuccess
}
);
});
function fnSuccess(msg)
{
$('div#placeHolder').html(msg);
}
function selectEditActivity(pass_id){
var row = $('#'+pass_id);
var seq = row.attr('seq');
// here I would like to pull the value of the date from the selected row
// but I just can't get syntax right. I get a null value on alert
var from_date = $('td', row).eq(0).html();
alert(from_date);
}
</script>
This is the html code that gets read in (file: status_2.html)
<span id="status2">
<span id="response" class="response"></span>
<table class="tableBorder">
<tr >
<th class="align_left">Date</th>
</tr><tr>
<tr seq="1" class="row_theme2" id="id3014201105191"></tr>
<tr><td>20090519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105191');" href="#">EDIT</a></td>
</tr>
<tr seq="2" class="row_theme2" id="id3014201105192"></tr>
<tr><td>20100519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105192');" href="#">EDIT</a></td>
</tr>
<tr seq="3" class="row_theme2" id="id3014201105193"></tr>
<tr><td>20110519</td>
<td>1330</td>
<td>1430</td>
<td>LUNCH</td>
<td></td>
<td><a onclick="selectEditActivity('id3014201105193');" href="#">EDIT</a></td>
</tr>
</tbody></table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此:更改
为:
...因为您要查找的信息位于具有 ID 的信息的下一行中。具有 ID 的行没有
元素。
实例: http://jsfiddle.net/kkP56/
编辑:您可以摆脱内联 onclick 处理程序,并让 jQuery 分配处理程序(如果您愿意)。
Change this:
to this:
...because the information you're looking for is in the next row over from the one with the ID. The row with the ID has no
<td>
elements.Live Example: http://jsfiddle.net/kkP56/
EDIT: You could get rid of the inline onclick handlers and let jQuery assign the handlers if you wanted.