我遇到jquery事件的问题。在我用另一个元素替换那个元素之后,多次调用Jquery事件,但是相同类型和相同的ID。ajax替换元素后多次发生事件调用
// 1. ajax call success and replace my block
// 2. This is my event that I want it happen.
$(document).on("click", ".polaroid button.addImage", function(event) {
event.preventDefault();
// trigger browse file to upload
$(event.target).closest("div.polaroid").find("input[type=file]").trigger("click");
});
此代码被用于转售AJAX成功后调用事件。那么,为什么button.addImage
与事件click
多次调用AJAX被称为? 这是HTML:
<div class="col-md-3 polaroid">
\t <img src="images/ingredient/default_img.png" title="Main image" />
\t <input type="file" name="file-image" style="display:none"/>
\t <button type="button" data-toggle="tooltip" title="Add" class="btn addImage"><i class="glyphicon glyphicon-plus icon-plus"></i></button>
</div>
你把这行多次?你只应该这样调用一次。如果你不能仅仅调用它一次,那么你需要解除它。 – epascarello
只有一次。我检查了。 – thanhlong
可能再次加载这个脚本 – charlietfl