0

我正在使用 AJAX JQuery 验证插件提交表单。代码看起来像这样:

$(document).ready(function(){
$("#myform").validate({
    debug: false,
    rules: {
        fname: {required: true}, 
        sname: {required: true}, 
        gender: {required: true}, 
    },
    messages: {
        fname: {required: " *"},
        sname: {required: " *"},
        gender: {required: " *"},
    },
    submitHandler: function(form) {
        $('input[type=submit]').attr('disabled', 'disabled');
        $('#results').html('Loading...');
        $.post('process_participant.php', $("#myform").serialize(), function(data) {
            $('#results').html(data);
        });
    }
});
}); 

现在问题是,在我将此信息发送到我的 PHP 页面以进行处理 (process_participant.php) 之后,我想用一个确认框进行响应,询问用户是否要添加另一个参与者。PHP 代码如下所示:

if (everything processes okay){

echo '<script type="text/javascript">';
echo 'input_box=confirm("Saved successfully. Would you like to add another participant?");
            if (input_box==true) {
                window.location = "new_participant.php"
            }   
            else {
                window.location = "home.php"
            }';
echo '</script>';  
}

这一切都很好,但默认的确认框是不可接受的。我需要能够对其进行样式设置并将其从 OK 和 CANCEL 更改为 YES 和 NO。我决定使用这个插件: http: //kailashnadh.name/code/jqdialog/并在 PHP 端使用以下代码:

echo '<script type="text/javascript">';

echo "  function confirmBox() {
                $.jqDialog.confirm(\"Are you sure want to click either of these buttons?\",
                function() { window.location = \"new_participant.php\"; },
                function() { window.location = \"home.php\"; }  
                );
            });";

echo "confirmBox();";

但是我似乎无法让它工作。也许我应该避免使用插件?整个 AJAX 事情让事情变得混乱。有人知道在这种情况下实现自定义确认框的最佳方法吗?

4

2 回答 2

0

从一开始就使用 display:none 创建框
,当来自 post 请求的函数返回
时进行检查(基于变量数据)
,如果一切正常,使用 jquery 的 show() 更改可见性

于 2012-09-20T15:10:32.297 回答
0

试试这个

它易于实现,只需为警报和符合框定义您自己的 html

于 2012-09-20T15:13:43.523 回答