Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/472.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用sweet alert confirm提交表单?_Javascript_Php_Jquery_Forms_Sweetalert - Fatal编程技术网

Javascript 如何使用sweet alert confirm提交表单?

Javascript 如何使用sweet alert confirm提交表单?,javascript,php,jquery,forms,sweetalert,Javascript,Php,Jquery,Forms,Sweetalert,我正在尝试在确认使用后提交表单。但是,不知何故,我的表单绕过了sweet alert confirm(未经确认发送) 我想做的是 新闻稿提交 警觉 如果单击“是”=发送表单 如果单击取消=关闭甜警报 这是我的剧本 $("#btn_submit").on('click',function(e){ //also can use on submit e.preventDefault(); //prevent submit var jns_srt = $("#i_dok").val(

我正在尝试在确认使用后提交表单。但是,不知何故,我的表单绕过了sweet alert confirm(未经确认发送)

我想做的是

  • 新闻稿提交
  • 警觉
  • 如果单击“是”=发送表单
  • 如果单击取消=关闭甜警报
这是我的剧本

$("#btn_submit").on('click',function(e){ //also can use on submit
    e.preventDefault(); //prevent submit
    var jns_srt = $("#i_dok").val();

    swal({
        title: "Are you sure?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes!",
        cancelButtonText: "Cancel",
        closeOnConfirm: true
    }, function () { 
        //I don't know what to write here. 
        });
});

 <form name="frm_input" id="frm_input_srt" method="post" action="<?php echo site_url('Admin/rekam_srt_msk'); ?>">
<table>
 <tr><td colspan="3" style="text-align:left; padding:0; vertical-align:middle"><input type="text" name="test" /></td></tr>
            <tr>
                <td colspan="3" style="text-align:center; padding:0; vertical-align:middle">
                    <input type="reset" id="btn_reset" name="btn_reset" class="btn btn-danger" value="Reset">
                    &nbsp;||&nbsp;
                    <input type="submit" id="btn_submit" name="btn_submit" class="btn btn-success" value="Save">
                </td>
            </tr>
            </table>
 </form>
$(“#btn_submit”)。在('click')上,函数(e){//也可以在提交时使用
e、 preventDefault();//防止提交
var jns_srt=$(“i#u dok”).val();
游泳({
标题:“你确定吗?”,
键入:“警告”,
showCancelButton:true,
confirmButtonColor:#DD6B55“,
confirmButtonText:“是的!”,
cancelButtonText:“取消”,
closeOnConfirm:true
},函数(){
//我不知道在这里写什么。
});
});

您可以通过Id获取表单元素,然后提交

document.getElementById("frm_input_srt").submit();
或者jquery方式

$("#frm_input_srt").submit();

文档显示了如何在取消和确认时运行不同的代码。直接从他们的:

对于您的代码:

$("#frm_input_srt").submit( function () {
    var jns_srt = $("#i_dok").val();

    swal({
        title: "Are you sure?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes!",
        cancelButtonText: "Cancel",
        closeOnConfirm: true
    }, function(isConfirm){
      if (isConfirm) {
        return true;
      } else {
        return false;
      }
    });
});
使用以下命令:

$("#btn_submit").on('click',function(e){ //also can use on submit
    e.preventDefault(); //prevent submit
    var jns_srt = $("#i_dok").val();

    swal({
        title: "Are you sure?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes!",
        cancelButtonText: "Cancel",
        closeOnConfirm: true
    }, function (getAction) { 
if (getAction.value === 'true') {
        // Insert code that will be run when user clicks Ok.
        });
});
这是你的答案

("#btn_submit").on('click',function(e){ //also can use on submit
e.preventDefault(); //prevent submit
swal({
    title: "Are you sure?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes!",
    cancelButtonText: "Cancel",
    closeOnConfirm: true
}
}).then(function(value) {
    if (value) {
      $('#frm_input_srt').submit();
    }
});

它仍在发送,但我没有点击Yes。在确认窗口中,它仍没有停止。当我点击按钮编辑表单时,我的表单未经确认就被发送。表单被简化了(我的实际表单很复杂),不幸的是没有。是否有任何js代码可能会冲突/覆盖此代码?或任何console.log错误?
$("#btn_submit").on('click',function(e){ //also can use on submit
    e.preventDefault(); //prevent submit
    var jns_srt = $("#i_dok").val();

    swal({
        title: "Are you sure?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes!",
        cancelButtonText: "Cancel",
        closeOnConfirm: true
    }, function (getAction) { 
if (getAction.value === 'true') {
        // Insert code that will be run when user clicks Ok.
        });
});
("#btn_submit").on('click',function(e){ //also can use on submit
e.preventDefault(); //prevent submit
swal({
    title: "Are you sure?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes!",
    cancelButtonText: "Cancel",
    closeOnConfirm: true
}
}).then(function(value) {
    if (value) {
      $('#frm_input_srt').submit();
    }
});