Home > Article > Web Front-end > JavaScript method to obtain elements through Chinese id and class
I used to think that id and class in html elements could only be named by special characters such as letters, numbers or underscores. If you use a Chinese browser for single storage, no error will be reported, but js cannot be obtained. However, when I visited the forum today Found this not to be the case.
The code is as follows:
Run result:
The forum source is this:
Forum link
The question requirements are as follows:
The forum master’s answer is as follows:
**var item = arr[i].split(':'),o;
(o = document.getElementById(item[0])) && (o.value = item[1]);**
Seeing these two lines, I found that item[0] should get the Chinese id, document.getElementById (item[0]) is the element that obtains the Chinese ID. After running, it was found that it can be obtained. This time I gained knowledge again.
**
Related recommendations:
Summary of JQuery’s methods of obtaining elements
Instance analysis of JavaScript methods and attributes for obtaining elements
Js setting and getting element style methods
The above is the detailed content of JavaScript method to obtain elements through Chinese id and class. For more information, please follow other related articles on the PHP Chinese website!