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