• Blogs (9)
    • đŸ“± 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • jQuery tips 1

    Blogs20142014-06-13


    1. form submit

    I found an interesting sample of ‘form submit’ in stackoverflow, and did some improvements to make it better: to rewrite the ’after()’ part to avoid ‘div#notice’ repeatedly generated.

    //use after() to replace 'beforeSend':
    jQuery(document).ready(function($) {
     $("#email_form")
      .after((function() {
        return $('#notice').length ?
          $('#notice').html('Loading...').fadeIn() :
          $('<div/>').prop('id', 'notice').html('Loading...').fadeIn();
      })
      .submit(function(e){
        e.preventDefault();
        $.post( '/email_router/', {email:$("#email").val()}, function(data){
          if( data.success ){
            $("#notice").html("Signup Is Successful.");
          } else {
            $("#notice").html("There was an error");
          }
        }, 'json');
      });
    });

    2. self.opener for iframe

    Communicate between parant and child window(e.g: iframe or dialog pop-window), use window.self.opener, or window.parent:

    self.opener.location.href = "page.htm";
    self.opener.focus().get_name(parent_window_name);
    window.parent.iframe[2].document.body);
    
    <INPUT TYPE="text" SIZE=25
     onChange="self.opener.document.forms[0].entry.value=this.value">