One way JavaScript must avoid using HTML elements

Source: Internet
Author: User

When we write the foreground page, we may often use the "javascript+ data" method of generating page elements, but when we have to deal with a large amount of data, resulting in the page needs to show too much control, the page response speed will be straight down.

We may often go to troubleshoot the cause of the problem, in fact, after troubleshooting the redundant loops and streamlining the number of controls, we found that performance is still not optimistic, so continue to troubleshoot, an accidental modification, but greatly improved efficiency, is similar to the following changes:
Before modification:

The code is as follows:
objdiv.innerhtml + = ' ";


After modification:

The code is as follows:
var Imga = document.createelement ("img");
Imga.setattribute ("src", "back.gif");
Imga.setattribute ("id", "picture");
Objdiv.appendchild (IMGA);


Before possible because of the convenience of writing, so did not use to create page elements, and then assign values, and finally nested methods, but directly through the string assignment innerHTML method, this method is relatively simple and convenient, but in terms of performance is still a loss, Because this inevitably involves a process of converting a string to the correct page control, where the performance loss is likely to be large, causing the page to be correspondingly sluggish.

Http://www.jb51.net/article/19442.htm

One way JavaScript must avoid using HTML elements

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.