【发布时间】:2013-06-26 02:45:00
【问题描述】:
下面的代码是使用 Ajax 调用动态生成的,并放置在名为 studentresults 的硬编码 div 中。
<div id="studentresults" class="row span8 offset2">
<table id="tablestudent" class="table table-striped table-hover center-table">
<thead>Heading for my table</thead<
<tbody>
<tr id="showstudents">
<td>29041</td>
<td>jan</td>
<td>jan</td>
<td>
<a class="btn" href="#">View Results »</a>
</td>
<td id="29041">
<a id="29041" class="btn showstudent" href="#">Delete Student » </a>
</td>
</tr>
<tr id="showstudents">
.... another dynamic record from Ajax...
</tr>
</tbody>
</table>
</div>
效果很好。但是,我想在 Delete Student 标记上再进行一次 Ajax 调用。我不明白如何为这个动态内容编写 jQuery 点击函数。
JQuery 调用不起作用
$('.showstudent').click(function(){
alert('In click');
});
但是这在硬编码的 div container 中有效
$('#studentresults').click(function () {
alert('In click');
});
如何访问动态<a> 内容
【问题讨论】:
-
您有多个具有相同 id 的元素。那不是有效的 HTML,您应该修复它,以便您可以通过 id 安全地选择元素。
标签: javascript html ajax jquery dynamic