我不明白为什么按钮点击事件发射2次....我在物化css上画了2张卡...当我按下按钮时它检查客户端会话是否开始,并且做某事......否则就会打开一个模态。但点击必须只发射1次,我得到2次警报(“chango”),点击1次......帮助PLS !!,这里是代码:
function list_section(data) {
var p = JSON.parse(data); // 2 results
$.each(p, function(i, item) {
if (item.SECTION_ID == 1) {
$("#president").append(
'<div class="col s6">' +
'\<div class="card medium sticky-action" id="president_'+item.POLITIC_ID+'">' +
'<div class="card-image waves-effect waves-block waves-light">' +
'<div class="video-container">' +
' <iframe src="' + baseurl + 'public/uploads/' + item.POLITIC_FILE + '" frameborder="0" allowfullscreen controls></iframe>' +
'</div>' +
'</div>' +
'<div class="card-action">' +
'<span class="card-title activator grey-text text-darken-4">' + item.POLITIC_NAME + ' ' + item.POLITIC_LASTNAME + '<i class="material-icons right">more_vert</i></span>' +
'<div class="row" style="margin-top:10px;margin-bottom:0px;">' +
'<div class="col s3">' +
'<button class=" btn waves-effect modal-trigger waves-light red darken-3 disapprove disapprove_president" data-target="verification" type="submit" name="action" ">Desapruebo</button>' +
'</div>' +
'<div class="col s3 offset-s4">' +
'<button class=" btn waves-effect modal-trigger waves-light light-green darken-3 aprove aprove_president" data-target="verification" type="submit" name="action" ">Apruebo</button>' +
'</div>' +
'</div>' +
'</div>' +
'<div class="card-reveal">' +
'<span class="card-title grey-text text-darken-4">' + item.POLITIC_NAME + ' ' + item.POLITIC_LASTNAME + '<i class="material-icons right">close</i></span>' +
'<p>Here is some more information about this product that is only revealed once clicked on.</p>' +
'</div>' +
'</div>' +
'<input type="hidden" id="' + item.POLITIC_ID + '">' +
'</div>'
);
$(document).on('click', '.aprove , .disapprove', function() {
// $(".aprove , .disapprove").unbind("click");
// $(".aprove , .disapprove").on("click", selectKeepFirstOfAll);
if (sesion != "") {
if ($(this).attr('class').split(' ').pop() == 'aprove_president') {
alert("chango");
var data = {}
$.ajax({
url: baseurl+'result/aprove',
type: 'POST',
data: data
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
}
else if ($(this).attr('class').split(' ').pop() == 'disapprove_president') {
}
}
else {
$('#verification').openModal();
}
});
}
答案 0 :(得分:0)
将$(document).on('click'...)
移到list_section
函数之外(使其成为全局)。您正在为您处理的每个部分添加一个onclick处理程序。