阻止脚本像本地确认一样使用jConfirm运行 [英] Prevent script from running using jConfirm like native confirm

查看:58
本文介绍了阻止脚本像本地确认一样使用jConfirm运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jConfirm上遇到问题,它应该可以像普通的javascript confim框一样工作,但事实并非如此,这是一个示例

i have a problem with jConfirm, it should work just like the normal javascript confim box but it doesn't, here's an example

<input type="submit" value="click" onClick="return jConfirm('are you sure?')">

如果我使用普通的确认,它将停止脚本,直到给出响应为止,但是使用jConfirm,即使没有给出答案,表单仍在提交,是否有任何解决方法?

If i use the normal confirm it stops the script until a response is given, with jConfirm however, the form is still being submitted, even if no answer is given, any workarounds?

预先感谢

使用Slaks的想法,我试图调整默认的jAlert插件,这就是我得到的.

Using Slaks idea i'm trying to tweak the default jAlert plugin, here's what i got.

submit: function(message, title, btnId) {
            $.alerts._show(title, message, null, 'confirm', function(result, btnId) {
                if (result){
                    var form = $('#'+btnId).closest('form');
                    form.trigger('submit');
                }           
                else
                    return false
            });
},

问题是我不知道如何将btnId变量传递给_show回调函数,

The problem is that i don't know how to pass the 'btnId' variable to the _show callback function, any thoughts?

推荐答案

最后,我像这样修复了它,将按钮发送给按钮(在调用函数时带有"this"),然后我可以获取表单,然后提交,我还可以在按下按钮时附加一个隐藏的输入,以便可以使用PHP执行适当的操作.

In the end i fixed it like this, sending the button the button (with 'this' while calling the function) i can get the form and then submit it, i can also attach a hidden input with the button pressed so i can execute the proper action with PHP.

submit: function(message, title, btnObj) {
            $.alerts._show(title, message, null, 'confirm', function(result) {
                if (result){
                    var form = $(btnObj).closest('form');
                    var input = '<input type="hidden" name="action" value="'+$(btnObj).attr('value')+'">';
                    $(form).append(input);
                    form.trigger('submit');
                }   
                else
                    return false
            });
        },

这篇关于阻止脚本像本地确认一样使用jConfirm运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆