我创建了一个struts2-jsp应用程序,我想要一个对话框弹出每当编辑超链接点击时,我使用Jquery弹出一个对话框时单击Edit超链接。 问题是只有当第一次编辑被点击时,对话框才会弹出,第二次和其他编辑是在添加记录时动态生成的,对话框不会弹出。jquery:对话框没有在动态生成的表中弹出
jQuery代码是:
<script>
$(document).ready(function(){
$("#todo").dialog({ autoOpen: false });
$("#dialogLink").click(function() {
$("#todo").dialog('open');
});
});
</script>
动态生成表的代码是:
<div class="content">
<table class="todoTable" cellpadding="5px">
<tr class=even>
<th>TITLE</th>
<th>STATUS</th>
<th>EDIT</th>
<th>DELETE</th>
</tr>
<!--This will iterate through the todolist -->
<s:iterator value="gettodoList()" status="todoStatus">
<tr class="<s:if test="#todoStatus.odd == true ">odd</s:if> <s:else>even</s:else>">
<td><s:property value="title" /></td>
<td><s:property value="complete" /></td>
<!-- This will append the Id with the url -->
<td>
<a id="dialogLink" href="#">Edit</a>
</td>
<td><s:url id="deleteURL" action="deleteTodo">
<s:param name="id" value="%{id}"> </s:param>
</s:url> <s:a href="%{deleteURL}">Delete</s:a>
</td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
[事件绑定动态创建的元素?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – vijayP
也'id'可能重复单一文件。尝试给予'class'而不是'id'并通过事件委托技术绑定事件。 – vijayP
确保在更新表后执行jquery代码。也许jQuery代码在开始时只执行一次 – Chandru