The javasript part of the website development, now the developer rarely have to hand write document.getElementById (), it is not exhausted, you really don't say, getElementById is really difficult to write, the letters are quite many and case-sensitive, I was wrong when I was not careful. So it's common to use $ to implement Document.getelemetnbyid ().
Copy Code code as follows:
function $ () {
var elements = new Array ();
for (var i = 0; i < arguments.length; i++) {
var element = Arguments[i];
if (typeof element = = ' String ')
element = document.getElementById (element);
if (arguments.length = 1)
return element;
Elements.push (Element);
}
return elements;
}
Microsoft's ASP.net AJAX client framework also has code similar to those implemented with $get.
Copy Code code as follows:
var $get = Sys.UI.DomElement.getElementById = function Sys$ui$domelement$getelementbyid (ID, Element) {
<param name= "id" type= "String" ></param> 4.5.
<param name= "Element" domelement= "true" optional= "true" maybenull= "true" ></param> 6.7.
<returns domelement= "true" maybenull= "true" ></returns> 8.9.
var e = function._validateparams (arguments, [
{name: ' id ', type:string},
{name: "element", Maybenull:true, Domelement:true, optional:true}
]);
if (e) throw e;
if (!element) return document.getElementById (ID);
. if (Element.getelementbyid) return Element.getelementbyid (ID);
Implementation for browsers so don ' t have getElementById on elements:28.29.
var nodequeue = [];
var childnodes = element.childnodes;
for (var i = 0; i < childnodes.length; i++) {
var node = childnodes[i];
if (Node.nodetype = = 1) {
Nodequeue[nodequeue.length] = node;
}
}
while (Nodequeue.length) {
node = Nodequeue.shift ();
if (node.id = = ID) {
return node;
}
ChildNodes = Node.childnodes;
for (i = 0; i < childnodes.length; i++) {
node = childnodes[i];
if (Node.nodetype = = 1) {
Nodequeue[nodequeue.length] = node;
}
}
}
return null;
}
Because of the simplicity and elegance of jquery and, more importantly, being promoted by Microsoft, the introduction of jquery into the project seems natural and inevitable, and jquery uses the $ function to return a jquery object, which is $=jquery, which is introduced into jquery for $ The symbolic problem inevitably produces the conflict, therefore has 2 main ideas to solve.
First, the use of Jquery.noconfict () makes $$ equal to JQuery, the code is $$=jquery.noconflict (). It takes a few things to do.
1. Finally add $$=jquery.noconflict () in jquery and jquery-based Javasript code files (jqueryxxx–vsdoc.js), jquery vs Smart hint file Also the final window.jquery = window.$ = jquery, also changed to Window.jquery = window.$$ = jquery; okay.
2, based on jQuery plug-ins and extension files at the front plus $=jquery.noconflict (), the most behind plus $$=jquery.noconflict ();
3, the original $ implementation file, the top plus jquery.noconflict () to the $ "power" to the other our own JS file, and then the file followed by the $$=jquery.noconflict ().
4, the page to introduce JS time to pay attention to the order, jquery related files in front, and jquery irrelevant files behind.
After doing so, $ still represents the previous meaning, and using jquery is straightforward with jquery or $$.
Advantages: Only need to change a few files to achieve the goal.
Disadvantages: $$ is not easy to use, after the introduction of the jquery plug-in will need to follow step 2 to operate once.
Second, replace the original $, after consideration I followed the next method, because jquery will be widely used in future projects, using $$ or jquery to write code is awkward. Considering the compatibility of ASP.net Ajax, replace the original $ to $get. It's not hard to replace it with Visual Studio.
, but it also requires a little step.
1, first with $get ("Replace $ ("), and then with $get (' Replace $ ('), the last is $get replaced with $.
2, when the replacement of the use of VSS checkout prompt function, a file for a certain confirmation (if there is a mistake that is not trivial). Finally, there are some small problems, with the assistance of colleagues has also been basically solved.
3, Visual Studio's replacement function is really the sleeve of the universe, such as the next replace in the files things are quite a lot.
Use that hook, do not choose regular expressions, because on the right clearly show $ for line. Look in that of course choose current Project, of course, the button on the right can select multiple directories to frame the rhetorical question, which is completely useless before. Look in these file types can be selected to narrow the scope by selecting some special types of files.