To digress, use If you create an object in json format, it is recommended that attributes do not require single quotes or double quotes, except for some ecmascript keywords, such as 'for', 'class', etc. above. It is recommended to use single quotes instead of single quotes. Quotation marks are definitely better than double quotation marks and more compliant with specifications, but a habit is still very important. Do not have single quotation marks and double quotation marks appearing in the code. A simple example:
If you want to get a certain attribute value of a DOM element directly through the access method elem.propertyName, you must make a simple change to the above attribute access,
For example, in the above example, you want to get the for attribute value of label.
var ele = document.getElementById('test'); var val = ele.htmlFor; //or val = ele['htmlFor']; //If accessed through standard DOM methods, no special processing is required val = ele.getAttribute('for'); val = ele.getAttributeNode('for').value;
Similarly for class, readonly, etc. access, the above types Access methods are equally suitable.
Personally, I think that accessing directly through attributes may be faster than accessing through DOM methods. The following article will introduce access to special attributes.
Statement:
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