【问题标题】:Cannot submit form using jquery无法使用jquery提交表单
【发布时间】:2019-09-22 15:29:28
【问题描述】:

我在使用 jquery 在 sweetalert2 中提交表单时遇到问题。

这是我的代码:

<?=form_open_multipart('controller_path','id="form_service"' , ''?>
<input type="button" name="update" id="submit-operate" value="Submit To Operated" class="btn btn-success" onclick="service.submitService()"/>
<?= form_close(); ?>

这是 service.js:

submitService: function(){
        swal({
            title: 'Are you sure?',
            text: "You will submit this service to the next phase",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Submit'
        }).then((result) => {
          if (result.value) {
                $("#form_service").submit()
            }
        });
    }

sweetalert 也可以,当我在if(result.value) 中执行console.log 时,它会显示在控制台上,但表单没有提交。有人可以告诉我正确的方法吗?谢谢。

【问题讨论】:

标签: javascript jquery html sweetalert2


【解决方案1】:

试试这个:

submitService = function(){
     var form = $("#form_service");
            swal({
                title: 'Are you sure?',
                text: "You will submit this service to the next phase",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Submit'
            }).then((result) => {
              if (result.value) {
                    form.submit(); //semicolon in the end
                }
            });
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多