Jquery .click 이벤트는 첫 번째 버튼 만 트리거합니다! 데이터를 반복하고 각 HTML 페이지에 버튼을 추가하고 클릭 할 때 각 버튼이 대화 상자를 트리거하는 것을 원합니다. 그러나 첫 번째 버튼 만 작동합니다! 나머지는 클릭 이벤트가없는 것 같습니다.Jquery .Click 이벤트는 루프의 첫 번째 버튼 만 트리거
$(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%>
ID가 btn_comment 인 페이지에 버튼이 두 개 이상 있습니까? ID는 고유해야합니다. – j08691
@ j08691 네 말이 맞아. 하나 이상의 클래스가있는 경우 클래스를 사용해야합니다. – Norse