我有一个要提交的表单,该表单将发布到 php 脚本以处理表单数据。
我需要做的是在点击提交后弹出一个带有 php 结果的彩框。
这可以做到吗?
这是我一直在尝试的:
$("#buildForm").click(function () { // #buildForm is button ID
var data = $('#test-buildForm'); // #test-buildForm is form ID
$("#buildForm").colorbox({
href:"build_action.php",
iframe:true,
innerWidth:640,
innerHeight:360,
data: data
});
return false;
});
UPDATE: This would need to be returned in an iframe as the build_action.php has specific included css and js for those results.
最佳答案
这是简单的、未经测试的代码,但它会为您提供一个很好的起点,因此您可以随心所欲地详细说明:
<form action="/path/to/script.php" id="formID" method="post">
<!-- form stuff goes here -->
<input type="submit" name="do" value="Submit" />
</form>
<script type="text/javascript">
$(function() {
$("#formID").submit(function() {
$.post($(this).attr("action"), $(this).serialize(), function(data) {
$.colorbox({html:data});
},
'html');
return false;
});
});
</script>
关于php - 提交表单(jquery)并在 colorbox 中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7737166/