Introduction
I encountered a problem today. This problem is also a problem I encountered before. The previous method is also used by most people. You can read my article.
Previous approach-I guess most people use it
For example, the following code is taken from a piece of js Code on the Sina homepage. This method is also used by most people.
What did you do after reading the above Code? You may change the form of + = to the push form of the array. Some people say that push is faster than this character link, but it is not much faster.
If there is a lot of embedded html code, do you want to handle it like this? If you want to modify, add, or delete an html file, you need to constantly flip the code, find the corresponding tag, and then find the end tag. Are you not in trouble? Some people may write this as early as I did, which is also the method I prefer most ).
The above code is also very difficult to maintain. Many times, if a tag is added to the ui or the html structure is modified, it is a headache for me.
Page templatification-A New Method
I recently read facebook's js Code. By chance, I found that the following method looks good and I hope to share it with you.
View my index.html code
View my js Code
Today, I accidentally discovered that this method is more reasonable, because the for loop is too disturbing.
It is easy to maintain the preceding html code. Next time, no matter what changes are made to the html code structure, it will be easy to change.
Post-repair
Yesterday, my project needed the conditional filtering function, so I made anotherIf Syntax Parsing.
Bright code:
Method
First of all, I would like to thank you for your valuable comments. Now I will post some comments, so do not be surprised. I am not satisfied with your comments.
1. Many people say that this code framework already exists, but I think this huge framework is used for a few simple functions. In addition, our existing code has a framework, maybe jquery, maybe prototype. js, and we have taken this framework. What kind of code is this!
2. I hope you do not have the habit of copying code at ordinary times. It is best to re-code the code, even your own code. -- Why I always use images.
3. There is no need to take the entire code. You can put the above two methods in your own code. -- You can fix the code yourself.
Link: http://www.cnblogs.com/baochuan/archive/2012/06/05/2537302.html
Edit recommendations]