2011-03-14 2 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 요소 자체)에 fadeOut을 사용하고 "감사합니다"요소에는 fadeIn을 사용합니다.

예 : 같은 코드를 사용하는

$("#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

+0

나는 완전한 예를 추가했습니다 –

관련 문제