请教一下关于在 PHP codeIgniter 中表单提交前使用 js 确认的问题。

2020 年 2 月 9 日
 dongchen

使用的是 bootstrap 4 和 bootboxjs

view

<?php echo form_open('panel/webconfig_post',array('class'=>'pt-4'));?>
...
...
<button class="btn btn-primary mr-5" type="submit" id='kk'>提交</button>    
<button class="btn btn-danger ml-5" type="reset">重置</button>

js

<script>
$(document).on("click", "#kk", function(e) {
    bootbox.confirm({
    message: "确定要提交吗?",
    locale: 'zh_CN',
    callback: function (result) {
        console.log(result);
        }
    });
});
</script>

想问下怎么写 js 才能点击窗口的确定之后再提交呢?

现在的情况是,点击提交,出现弹窗,但是不用点击直接提交表单到panel/webconfig_post这个控制器了

不会 js 😂

3434 次点击
所在节点    PHP
6 条回复
U2Fsd
2020 年 2 月 9 日
LZ 不看文档的吗?

```
bootbox.confirm({
message: "This is a confirm with custom button text and color! Do you like it?",
buttons: {
confirm: {
label: 'Yes',
className: 'btn-success'
},
cancel: {
label: 'No',
className: 'btn-danger'
}
},
callback: function (result) {
console.log('This was logged in the callback: ' + result)
}
})

```
U2Fsd
2020 年 2 月 9 日
result 会返回 true 或者 false
dongchen
2020 年 2 月 9 日
@U2Fsd 返回 true 或者 false 之后怎么处理呢?对 js 不是很懂😭
U2Fsd
2020 年 2 月 10 日
@dongchen

根据 true false 判断要不要提交表单
dongchen
2020 年 2 月 10 日
@U2Fsd .......不会写才问的
commoccoom
2020 年 2 月 10 日

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.ih06.com/t/643262

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX