Home  >  Article  >  Web Front-end  >  Questions about querySelectorAll() under IE8_javascript skills

Questions about querySelectorAll() under IE8_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:27:461556browse

When using querySelector() or querySelectorAll() to find elements with name="2nd_btn", FF, chrome and IE8 will all report errors.
FF, the error reported by chrome is the same, as shown below:
Error: uncaught exception: [Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR )" location: ".../test/qsa.html Line: 18"]
IE8 error message: Line: 18 Error: Invalid parameter.
After thinking about it, the value of name starts with a number. You can get it by removing or modifying the number.
This tells us that when generally customizing the attribute value of a label, the attribute value cannot start with a number, nor can it contain uncommon characters such as $ and ^.
Be sure to remember to declare at the beginning of the HTML page.

Test code:


Copy code The code is as follows:







This is another sample warning
< ;a name="1err" href="">This is another sample error

<script> <br>var a = document.querySelectorAll("[name =warns]") <br>alert(a.length)//Output: 2 <br>var b = document.querySelector("[id=3err]") <br>alert(b.tagName)//error report<br>var c = document.querySelectorAll("[name=1err]") <br>alert(c.length)//error report<br></script>

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