IE8 the problem of Queryselectorall () _javascript Skills

Source: Internet
Author: User
When you look for elements similar to name= "2nd_btn" with Queryselector () or Queryselectorall (), both Ff,chrome and IE8 make an error.
The ff,chrome of the newspaper is the same, as follows:
Error:uncaught exception: [Exception ... "An invalid or illegal string is specified" code: "A" Nsresult: "0x8053000c (Ns_error_dom_syntax_err)" Location: ".../te St/qsa.html line:18 "]
IE8 Error Prompt: line: 18 Wrong: parameter is invalid.
One thought, the value of name begins with a number, and the number is removed or modified to be taken.
This tells us that when a property value for a label is generally customizable, the property value cannot begin with a number, nor can it contain infrequently used characters such as $,^.
At the beginning of the HTML page be sure to remember to declare <! Doctype>.

Test code:


Copy Code code as follows:

<! Doctype>
<body>
<div id= "foo" >
<a N Ame= "warns" href= "" >this is a sample warning</a>
<a id= "3err" href= "" >this is a sample Error</a> ;
</div>
<div id= "Bar" >
<a name= "warns" href= "" >this is another sample warning</a>
<a name= "1err" href= "" >this is another sample error</a>
</div>
<script>
var A = Document.queryselectorall ("[Name=warns]")
Alert (a.length)//output: 2
var b = Document.queryselector ("[Id=3err] ")
Alert (b.tagname)//error
var c = Document.queryselectorall (" [Name=1err] ")
Alert (c.length)/error
</ Script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.