Jquery .click 事件只触发第一个按钮!我遍历数据并在我的html页面上为每个按钮添加按钮,并希望每个按钮在单击时触发一个对话框。但只有第一个有效!其余的似乎没有点击事件。
$(document).ready(function () {
$("#btn_comment").click(function () {
$("#createComment").dialog(
{
modal: true,
height: 300,
width: 500,
buttons: {
"Create a Comment": function () {
var post_id = $(this).parent().attr("id");
var desc_to_create = $("#txtComment").val();
$.post("CreateComment", { "id": "", "username": "x", "post_id": post_id, "description": desc_to_create, "created": "" }, function (t) {
alert("Thank you! Your comment has been updated!!");
location.reload();
})
},
"Cancel": function () {
$(this).dialog("close");
}
}
}
);
})
})
<tr id='<%= Html.Encode(item.id) %>'>
<td>
<%: Html.ActionLink("Details", "Details", New With {.id = item.id})%> |
<a href="javascript://" class="delete_btn">Delete</a>
</td>
<%-- <td>
<%: item.id %>
</td>
<td>
<%: item.username %>
</td>
<td>
<%: item.title %>
</td>--%>
<td>
<%: item.description %>
</td>
<td>
<input id="btn_comment" type="button" value="Add a Comment" />
</td>
<td>
<div id="new_comment"></div></td>
</tr>
<% Next%>