0

我需要帮助将数据表单#send_form 提交到另一个页面中的#f_from。

<script type="text/javascript">
function post_form() {
    $('#send_form').action = "form01.html";
    $('#send_form').submit();
    return false;    
}
</script>

<form id='send_form' action='form01.html' method='POST' onsubmit="post_form();">
<input type="text" name="f_in01" value="User" />
<input type="text" name="f_in02" value="12345" />
<input type="submit" />
</form>

form01.html

<script type="text/javascript">
function f_res()
{
    var res01=document.f_form.f_in01.value;
    var res02=document.f_form.f_in02.value;
    var result = res01 + " " + res02;
    document.f_form.f_out01.value=result;
}
</script>

<form id="f_form" onSubmit="f_res();return false;">
<input type="text" name="f_in01" /><br>
<input type="text" name="f_in02" /><br>
<br>
<input type="submit" onClick="f_res();" value="Enter w/Sub" /><br>
<input type="text" name="f_out01" />
</form>

现在它不起作用。数据未在 page01.html 中发布

4

3 回答 3

0

Amin is right, but in jQuery, when an event handler returns false, it amounts to the same as e.preventDefault(); e.stopPropagation(). Essentially, you cancel the event. Try returning true, instead of false.

If you don't want the page to change, you'll have to look at AJAX to post the form data.

于 2012-07-02T22:07:02.943 回答
0

您需要 AJAX 来解决这个问题,例如:

    $('#button').click(function(){
    $.ajax({
    type:"POST", //php method
    url:'process.php',//where to send data...
    cache:'false',//IE FIX
    data: data, //what will data contain (no SHIT Sherloc...)

    //check is data sent successfuly to process.php
    //success:function(response){
    //alert(response)
    //}

    success: function(){ //on success do something...

    $('.success').delay(2000).fadeIn(1000);

    //alert('THX for your mail!');
    } //end sucess 
    }).error(function(){ //if sucess FAILS!!
    alert('An error occured!!');
    $('.thx').hide();
    });
    });
于 2012-07-02T22:28:31.040 回答
0

你有没有尝试过

$('#send_form').attr('action', "form01.html");

代替

$('#send_form').action = "form01.html";

看看这个小提琴

于 2012-07-02T21:40:43.777 回答