This was discovered by sina's colleague xiaoniu. The difference between querySelector and getElementById in retrieving elements through id is found by sina's colleague xiaoniu, as follows:
The Code is as follows:
Script
Var str = '02e503e2a1c011cfc85b7b701a0677ec0900000000000001 ';
Function bySelector (id ){
Return document. querySelector ('#' + id );
}
Function byId (id ){
Return document. getElementById (id );
}
Alert (bySelector (str ));
Alert (byId (str ));
Script
The bySelector and byId functions obtain the element through querySelector and getElementById respectively.
The page contains the element "02e503e2a1c011cfc85b7b701a0677ec090000000001.
Result: none of the browsers that support querySelector can be obtained through bySelector (an error is reported), but can be obtained through getElementById.
It is suspected that the string of the id is too long, and the querySelector cannot be obtained. The real reason is that querySelector is implemented according to css specifications, that is, the css identifier cannot start with a number.
W3 writes
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U + 00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item ). for Instance, the identifier "B & W? "May be written as" B \ & W \? "Or" B \ 26 W \ 3F ".