일부 이벤트를 호출 할 때이 클릭 기능을 사용합니다. 그러나 클래스를 클릭 할 때 두 번, 세 번 이상 발사하는 경우가 많습니다.클릭 기능 언젠가 두 번, 세 번 이상 발포
이 코드에 대한 올바른 제안과 해결 방법을 알려주십시오.
$(".PositiveReaction").unbind("click").click(function() {
var itemGraphId = this.id;
itemGraphId = itemGraphId.replace("Like", "");
$.ajax({
type: "Post",
url: "/React/AddReact",
dataType: "JSON",
data: { "itemGraphId": itemGraphId, "reactionTypeEnum": "POSITIVE" },
success: function (data) {
$.each(data, function (i, item) {
$("#CountLike" + item.GraphID).html(item.CountPositiveReactions);
$("#CountDisLike" + item.GraphID).html(item.CountNegativeReactions);
});
},
error: function (req, status, error) {}
});
});
http://api.jquery.com/event.stoppropagation/ – MarsOne
.off/.on이 좋습니다. – mplungjan
그냥 제안, 함수 (함수 x() {}) 및 onClick = "x(); 사용하여 코드를 넣으십시오 관련 html 요소에 –