我創建了一個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