I have a initializor.js that contains the following:
if(typeof jQuery=='undefined')
{
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = 'jquery.js';
headTag.appendChild(jqTag);
}
I am then including that file somewhere on another page. The code checks if jQuery is loaded, and if it isn't, adds it to the Head tag.
However, jQuery is not initializing, because in my main document, I have a few events declared just to test this. I also tried writing some jQuery code below the check, and Firebug said:
"jQuery is undefined".
Is there a way to do this? Firebug shows the jquery inclusion tag within the head tag!
Also, can I dynamically add code into the $(document).ready()
event? Or wouldn't it be necessary just to add some Click events to a few elements?
question from:
https://stackoverflow.com/questions/6813114/how-can-i-load-jquery-if-it-is-not-already-loaded 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…