是否可以一键提交两份表格?一个表单的值由 JavaScript 生成,另一个表单由 PHP 生成。
我举了一个例子来说明我正在尝试什么。
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<?php
Class testing{
function text_test(){
?>
<form method="post" name="postform">
<input type="textbox" name="text"/>
<input type="submit" onclick ="submit_form()" name="submit"/>
</form>
<?php
}
function display(){
echo $_POST['text'];
echo $_POST['js_input'];
}
}
$test = new testing();
$test->text_test();
if(isset($_POST['js_form'])){
$test->display();
}
?>
<script type="text/javascript">
var jsvariable = "js_test";
</script>
<form method="post" name="js_form">
<input type="hidden" name="js_input" value="document.getElementByName(jsvariable).value" />
</form>
<script type="text/javascript">
function submit_form(){
$('postform').each(function () {
$(this).ajaxForm(); //Initialize as ajaxForm
var options = {
context: this
}
$(this).ajaxSubmit(options); //Submit form with options above
});
$('js_form').each(function () {
$(this).ajaxForm(); //Initialize as ajaxForm
var options = {
context: this
}
$(this).ajaxSubmit(options); //Submit form with options above
});
}
</script>