我正在使用 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 事情让事情变得混乱。有人知道在这种情况下实现自定义确认框的最佳方法吗?