我正在学习jQuery并尝试提交一个表单 - 如果在模态窗口中弹出的条款和条件被接受,则提交表单,否则关闭它。 我正在使用提交处理程序和ajax进行表单提交,但它不起作用(它没有将我带到操作URL)。谁能请帮忙。这是代码:
<form action="www.google.com" method="post" id="registration" novalidate="novalidate" enctype="plain/text" autocomplete="off">
........
</form>
<div class="modal hide" id="myModal" data-backdrop="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
.........
</div>
<div class="modal-body">
Please study the terms and conditions below and click "Yes" to Submit. Click "No" to cancel.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="button" class="btn btn-primary">Yes</button>
</div>
</div>
</div>
</div>
$("#registration").validate({
rules: {
......
},
messages: {
.......
},
submitHandler: function(form){
$.ajax({
url: $(form).action,
method: $(form).method,
data: $(form).serialize(),
success: function(data) {
jQuery.noConflict();
$("#myModal").modal('show');
// Submit on clicking "Accept"
$("#myModal .btn-primary").click(function(){
//alert("Clicked on "Accept");
$("#myModal").modal('hide');// this is working
$(form).submit(); // this is not working
});
}
})
}
});
return false;
答案 0 :(得分:1)
首先你要做的就是你需要准备好所有参数点击&#34;提交&#34; 然后只做一个等效(同步/同步)调用点击&#34;是&#34; 否则不要致电提交并向其显示相关信息
function submitForm(){
$("#submit").on('click',function(){
// write your logic for getting all the informatioon from the form that you would like to submit
//now write code for
// show the popup of confirmation. else
});
// make ajax call on click on "yes" of popup
$("#yes").on('click,function(){
// make ajax call here with parameters you get on click with sumit button's click
});
$("#no").on('click,function(){
// write appropriate message or executuion you want.
});
}
&#13;
答案 1 :(得分:0)
你能解释一下你想达到的目标(预期结果)......?
是的,有一点我不知道你为什么要使用&#34; jQuery.noConflict(); &#34; ,因为当您可能与 jQuery 或 $ 对象发生冲突时使用