Home > Web Front-end > JS Tutorial > body text

JavaScript method to obtain elements through Chinese id and class

小云云
Release: 2018-03-15 16:16:11
Original
2141 people have browsed it

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:

JavaScript method to obtain elements through Chinese id and class

Run result:

JavaScript method to obtain elements through Chinese id and class

The forum source is this:

Forum link

The question requirements are as follows:

JavaScript method to obtain elements through Chinese id and class

The forum master’s answer is as follows:

JavaScript method to obtain elements through Chinese id and class

**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.

**

Reminder: Although js can obtain Chinese IDs, it is not recommended to use Chinese as ID or class naming. After all, every development must follow development specifications.

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!