Jquery: when to start execution of EN en. ready ()

Source: Internet
Author: User

When does documen. ready () start execution?
 
After all DOM structures in the web page are drawn, they are executed. Can be abbreviated as: $ (function (){});
 
 
 
But let's look at this Code:
 
<Script type = "text/javascript">
Var maxfile = 5; // maximum number of files
Var filecount = 1; // file counter
$ (Function (){

// Add a file
$ ("# AddAttach"). click (function (){
If (filecount> maxfile ){
Alert ("You have exceeded the number of files allowed to be uploaded! ");
Return false;
}
Filecount ++;
Var content = "<div> <input type = 'file'>" + "<a href = '# 'class = 'del'> Delete
 
Attachment </a> <br/> </div> ";
$ ("# Files"). append (content );
 
// Register a deletion event
DeleteAllDiv ();
});
});
 
// Delete
DeleteAllDiv = function (){
$ ('. Del'). click (function (){
$ (This). parent ("div"). remove ();
Filecount --;
});
};
</Script>
 
 
 
Content was drawn by ourselves later! DOM does not have this structure at the beginning of loading! It is useless to write it in en. ready!
 
 
 
So we wrote it in $ ("# addAttach"). click.
From Xu Yue's column

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.