我从来没有在jQuery的工作过。这是我第一次。我需要一些确认对话框。我已经写这个在我的项目中应用之前先测试它。我写了这段代码。只有在指定的单选按钮被选中时,我才需要对话框。确认对话框不显示
主要问题:显示确认对话框如果在单选按钮指定的选项被选择。
Jquery的代码:
(function($){
$.fn.checkLeave = function() {
return this.each(function(){
if($("input[name='second']").is(':checked')) {
alert("Second Radio Button is CLicked");
$.confirm({
text: "Are you sure to submit the form",
title: "Confirmation required",
confirm: function(button) {
$("form").submit();
},
cancel: function(button) {
// nothing to do
},
confirmButton: "Yes",
cancelButton: "No",
post: true,
confirmButtonClass: "btn-default",
cancelButtonClass: "btn-danger",
dialogClass: "modal-dialog modal-lg"
});
}
});
};
})(jQuery);
和HTML是:
<form action="dialogJquery.html" method="post">
<input type="text" name="username" placeholder="Username">
<input type="radio" id="first">
<input type="radio" name="second" checked="">
<input type="submit" value="Submit" id="submit" name="confirm"
onclick="$(this).checkLeave();"></button>
</form>
上面的代码显示对话框之前定义的警报。但是之后没有显示对话框。这是我从哪里使用Jquery Dialog Plugin。但通过调试时,调试器达到$ .confirm,我点击步骤,然后对话框显示,但是当我恢复脚本它再次消除。
现在调试器甚至不来,如果条件。 –
它对我来说确切的HTML和脚本。你有没有改变你的HTML到我提供的? –
是的,我已经改变了你所写的一切。 –