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