Home  >  Article  >  Web Front-end  >  How to solve the problem that the DOM element does not distinguish the case of the name attribute under the IE8 browser

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

一个新手
一个新手Original
2017-10-17 10:30:232145browse

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;/>

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

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

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")

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!

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