我有jQuery代码:
$("#forcedcancel").on("click", function(e){
e.preventDefault();
$("#forceDialog").remove();
// get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
// calculate the values for center alignment
var dialogTop = (maskHeight/3) - 20;
var dialogLeft = (maskWidth/2) - 200;
var forcedialog = "";
forcedialog += '<div id="forceDialog" style="margin:'+dialogTop+'px 0 0 '+dialogLeft+'px;z-index:10;position:absolute;border: 1px #000 solid ;padding: 20px 20px 20px 20px;background-color:#fff">';
forcedialog += '<h3>Reason for force cancelling the lesson</h3>';
forcedialog += '<p><textarea id="forcereason" style="width:475px;height:121px"></textarea><p>';
forcedialog += '<button id="submitforce" class="btn btn-primary">Submit</button><button id="cancelforce" class="btn btn-danger">Cancel</button>'
forcedialog += '</div>';
$('body').prepend(forcedialog);
});
$("#forceDialog").on("click", "#cancelforce", function(){
alert("HERE");
$("#forceDialog").hide("slow");
});
当我单击 id="forcedcancel" 的按钮时,会显示 id="forceDialog" 的自定义对话框。但是,当我单击该 div 内的取消按钮时,alert("HERE") 不会触发。我太累了,没注意到我猜的错误。:(