2011-03-14 82 views

回答

1
<script type="text/javascript"> 

    function submitandhide(){ 

     $("#form").hide(); 
     /** 

      send you ajax request and on success 
      show thank you message 

     **/ 


     $("#thankyou").show(); 
    } 
</script> 

<form id="form">  
    <input type="text" /> 
    <input type="submit" onclick="submitandhide(); return false;"/> 
</form> 
<div style="display:none" id="thankyou"> 
    THANK YOU 
</div> 
0

基本上,您會在包含表單的元素(可能是form元素本身)和fadeIn的「謝謝」元素上使用fadeOut

實施例:

$("#theForm").submit(function() { 
    var form = $(this); 

    // You'd do your `ajax` call here; I'll use `setTimeout` 
    // instead just to emulate the asynchronous nature of 
    // the `ajax` call 
    setTimeout(function() { 
    // This function would be your `success` callback 
    form.fadeOut("fast", function() { 
     // This is the callback when the `fadeOut` is complete; fade in the "thanks" 
     var thanks = $("<p>Thank you!</p>"); 
     thanks.hide(); 
     form.replaceWith(thanks); 
     thanks.fadeIn("fast"); 
    }); 
    }); 

    return false; // Prevent form submission 
}); 

Live copy

+0

嘗試使用類似的代碼:form = document.getElementById('form')當時$(form).hide() Jay 2011-03-14 06:31:06

+0

我添加了一個完整的例子 – 2011-03-14 06:32:39