【问题标题】:Show a Modal Window on Form Submit and Submit form While Modal "Accept" Button is clicked?单击模态“接受”按钮时,在表单提交和提交表单上显示模态窗口?
【发布时间】:2013-08-10 10:41:14
【问题描述】:

我有一个已经存在验证的表单,当我提交表单时,我显示了引导模式窗口,知道模式窗口有两个按钮接受和取消,点击接受按钮我希望表单提交和取消关闭模态框。

var errorMessages = [];

    $("#f").submit(function(event){

         $("input,select,textarea").not("[type=submit]").each(function (i, el) {
           errorMessages = errorMessages.concat(
               $(this).triggerHandler("validation.validation")
           );
         });     
    if(errorMessages.length==0){     
    $('#myModal').modal("show");
    $("#agreesubmit").on('click',function(){
        $("#myModal").modal("hide");
       return true;  
      });
    }
    event.preventDefault();
    });

现在我在点击#agreesubmit 按钮时卡住了,我想提交表单,但不知道在这里做什么。

【问题讨论】:

  • 当我点击同意提交按钮时,表单没有提交,我在提交表单时打开“条款和条件”模式,在那个模式上我有#agreesubmit 按钮,当我点击那个按钮时我希望表单最终提交那没有发生。
  • 你有它的实时链接吗?还是小提琴?

标签: jquery forms twitter-bootstrap


【解决方案1】:

这有帮助吗?基本上你需要一个“标志”来表示协议已经达成,然后提交表格。我已经展示了一个正在使用的数据属性,因为它简洁明了。 我没有测试过这段代码,但它在逻辑上是合理的。

$('#f').on('submit', function(e) {
  if( $(this).data('form-agree') !== true ) {
    e.preventDefault();
    // fire modal logic here.
  }
});

$('#agreesubmit').on('click', function() {
  $('#f').data('form-agree', true).submit();
});

【讨论】:

  • 谢谢哥们 这肯定有帮助:-)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-18
  • 2018-05-04
  • 1970-01-01
  • 1970-01-01
  • 2016-02-02
  • 1970-01-01
相关资源
最近更新 更多