我在按模式按钮时遇到问题(使用FullCalendar
)。
我的计划是:
当我尝试一次时效果很好。但是当我关闭模态并打开另一个时,我点击拒绝/确认按钮然后它会运行更多次(2,4 ...)。 有什么问题??
模态:
<div id="eventContent" title="Event Details" style="display:none;">
Name: <span id="name"></span><br>
Start: <span id="startTime"></span><br>
End: <span id="endTime"></span><br><br>
<p id="eventInfo"></p>
<button id="confirm_button" type="button">Confirm</button>
<button id="refuse_button" type="button">Refuse</button>
<button type="close_button">Close</button>
</div>
eventRender:
<script>
$(document).ready(function () {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'prev title next',
right: ''
},
events: "http://localhost/calendar_directory/calendar_db_connect.php",
eventRender: function (event, element) {
element.click(function () {
var start = $.fullCalendar.formatDate(event.start, "YYYY-MM-DD");
var end = $.fullCalendar.formatDate(event.end, "YYYY-MM-DD");
$("#name").html(event.title);
$("#startTime").html(start);
$("#endTime").html(end);
$("#eventContent").dialog({modal: true, title: event.title, width: 350});
$("#refuse_button").click(function ()
{
var id = event._id;
var confirmed_number = 2;
var decision = confirm("Do you really want to refuse that?");
if (decision)
{
$.ajax({
url: "http://localhost/calendar_directory/confirm_events.php",
data: '&id=' + id + '&confirmed_number=' + confirmed_number,
type: "POST",
success: function (json)
{
console.log(id);
return;
}
});
}
});
$("#confirm_button").click(function ()
{
var id = event._id;
var confirmed_number = 1;
var decision = confirm("Do you really want to confirm that?");
if (decision)
{
$.ajax({
url: "http://localhost/calendar_directory/confirm_events.php",
data: '&id=' + id + '&confirmed_number=' + confirmed_number,
type: "POST",
success: function (json) {
console.log("confirmed");
return;
}
});
}
})
});
},
});
});
</script>
确认列可以是:0,1或2
答案 0 :(得分:0)
为click事件分配了相同的处理程序。
解决方案是:
$("#refuse_button").unbind("click").click(function(){
/*Your code goes here*/
}
$("#confirm_button").unbind("click").click(function(){
/*Your code goes here*/
}