About JavaScript templates

Source: Internet
Author: User

When analyzing the Dropbox web interface, we can see some

<SCRIPT type = "text/template"> </SCRIPT>

There are many <% html = XX %> <% ATTR = YY %>

Tags. It seems confused.

Google is a technology called JavaScript template. The general principle is that the browser ignores the content because it does not know the <SCRIPT type = "text/template"> </SCRIPT> label. Therefore, this script can add some template content, and then call the template function to change the content (replace <% ATTR = %> with the required content ), then generate valid HTML content and add it to the DOM tree.

The implementation of the Dropbox multi-language version is also based on this:

All the text displayed in it will be displayed in different places according to different languages. The default value is the English value. After loading, execute the update_i18n_messages function to replace all the replacement places. The text displayed for dynamically added content (with the following data taken) is different. The Script Template is used to fill the content with the template function after the server returns data in JSON format, add to the DOM tree.

But implement it by yourself !!!???

Not onlyCodeLack of understanding, insufficient use of language, the most lacking is the understanding of the architecture, implementation!

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.