In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail about the JQuery ID selector can not contain special characters in the processing methods, the content of the article is of high quality, so the editor to share for you to do a reference, I hope you have a certain understanding of the relevant knowledge after reading this article.
The cause of the problem is that the ID of the dynamically generated Dom element contains a "=" (you may ask why there is a "=" sign in ID, I can only say that this is rare, but there are, as in my case, my ID is a string encoded by a string Base64).
This is true in versions 1.2.6 to 1.3.2 of JQuery. Here is the code for the test:
View plaincopy to clipboardprint?
$(function () {)
Var div= $("# hellodiv=")
If (div.length > 0) {
Alert ("got Div")
}
Else {
Alert ("Gee ID cannot contain =")
}
Var div2 = document.getElementById ("hellodiv=")
If (div2) {
Alert ("I can get it")
}
Else {
Alert ("Oh, I can't get it either")
}
});
$(function () {)
Var div= $("# hellodiv=")
If (div.length > 0) {
Alert ("got Div")
}
Else {
Alert ("Gee ID cannot contain =")
}
Var div2 = document.getElementById ("hellodiv=")
If (div2) {
Alert ("I can get it")
}
Else {
Alert ("Oh, I can't get it either")
}
});
Looking at the source code of Jquery, you can see that the parsing of the heap selector has this paragraph:
View plaincopy to clipboardprint?
Var match = quickExpr.exec (selector)
/ / Verify a match, and that no context was specified for # id
If (match & & (match [1] | |! context)) {
/ / HANDLE: $(html)-> $(array)
If (match [1])
Selector = jQuery.clean ([match [1]], context)
/ / HANDLE: $("# id")
Else {
Var elem = document.getElementById (match [3])
Var match = quickExpr.exec (selector)
/ / Verify a match, and that no context was specified for # id
If (match & & (match [1] | |! context)) {
/ / HANDLE: $(html)-> $(array)
If (match [1])
Selector = jQuery.clean ([match [1]], context)
/ / HANDLE: $("# id")
Else {
Var elem = document.getElementById (match [3]), where quickExpr is a regular expression object
QuickExpr = / ^ [^] * $| ^ # ([\ w -] +) $/
^ # ([\ w -] +) $is the ID selector and obviously can only match any English character number and underscore that includes an underscore.
So other characters such as = @ will have problems. Your solution is to modify the regular expressions in the JQuery code
If I want to add the = sign, then I can change it to quickExpr = / ^ [^] * $| ^ # ([\ w -\ =] +) $/
Or avoid the occurrence of ID with =.
On the JQuery ID selector can not contain special characters in the processing methods to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.