Home > Web Front-end > JS Tutorial > A method that must be avoided when handling HTML elements_javascript tips

A method that must be avoided when handling HTML elements_javascript tips

WBOY
Release: 2016-05-16 18:48:51
Original
993 people have browsed it

We may often investigate the cause of the problem. In fact, after eliminating redundant loops and reducing the number of controls, we found that the performance was still not optimistic, so we continued to investigate. An accidental modification greatly improved the efficiency, something like The following modifications:
Before modification:

Copy the code The code is as follows:

objDiv.innerHTML = '';

After modification:
Copy code The code is as follows:

var imga = document.createElement("img");
imga .setAttribute("src","back.gif");
imga.setAttribute("id","picture");
objDiv.appendChild(imga);

before Perhaps because of the convenience of writing, we did not use the method of creating page elements, assigning values ​​separately, and finally nesting them. Instead, we directly assigned innerHTML through strings. This method is relatively simple and convenient, but it still has some disadvantages in terms of performance. What is lost, because this must involve a process of converting the string into the correct page control, the performance loss may be relatively large, thus causing the corresponding slowness of the page.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template