简体   繁体   English

jQuery / Javascript表单帮助吗?

[英]Jquery / Javascript form help?

I have implemented this solution.. 我已经实现了这个解决方案。

http://tutorialzine.com/2010/10/ajaxed-coming-soon-page/ http://tutorialzine.com/2010/10/ajaxed-coming-soon-page/

However, on submit, I would like the form to disappear and the "thank you" text displayed. 但是,提交后,我希望表格消失,并显示“谢谢”文本。 Currently, the form remains and the "thank you" text is displayed in the textbox. 当前,该表单仍然保留,并且在文本框中显示“谢谢”文本。

What would I have to change? 我要改变什么?

Thank you! 谢谢!

<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>

Fundamentally, you'd use fadeOut on the element containing the form (perhaps the form element itself) and fadeIn on a "thank you" element. 从根本上讲,您将在包含表单的元素上使用fadeOut (也许是form元素本身),并在“谢谢”元素上使用fadeIn

Example: 例:

$("#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 即时复制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM