How to solve the problem that the DOM element does not distinguish the case of the name attribute under the IE8 browser

一个新手
Release: 2017-10-17 10:30:23
Original
2190 people have browsed it

When using the name attribute to obtain the dom element under the IE8 browser, it is not case-sensitive.
For example:

<input type=&#39;text&#39; name=&#39;C1&#39;/>
<input type=&#39;text&#39; name=&#39;c1&#39;/>
Copy after login

There are two input boxes as above, their name attributes are uppercase C1 and lowercase c1 respectively
When getting elements, use jqury under Google Chrome to get:

$("input[name=&#39;c1&#39;]").length // 1
Copy after login

The DOM element obtained when the above code is run under I8 is 2.
Change to js native method to obtain:

document.getElementsByName(&#39;c1&#39;).length document.querySelectorAll("input[name=&#39;c1").length
Copy after login

The above two methods are both 2 under IE8. It can be seen that the name attribute under IE8 is not case-sensitive.
When encountering these problems, we can add its parent element to distinguish the selection when selecting the dom element:

<p class=&#39;p1&#39;><input type=&#39;text&#39; name=&#39;C1&#39;/></p>
<p class=&#39;p2&#39;><input type=&#39;text&#39; name=&#39;c1&#39;/></p>
document.querySelectorAll(".p1 input[name=&#39;C1")
document.querySelectorAll(".p2 input[name=&#39;c1")
Copy after login

This solves the problem that IE8 cannot distinguish the case of the name attribute. question.

The above is the detailed content of How to solve the problem that the DOM element does not distinguish the case of the name attribute under the IE8 browser. 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!