jQuery is not loaded
jQuery is not loaded
我有这样的代码,但console.log没有带来任何东西,当我尝试在控制台中键入时,我可以看到它被加载了,但当我加载这个脚本时,它没有给控制台带来任何东西——jQuery函数也不起作用。以下代码:
var bbimagebannerfile = "/300x250.jpg";
document.write("<a href='"%%__REDIRECT%%'" target='"_blank'"><img src='"" + bbimagebannerfile + "'" border='"0'" /></a>");
if (typeof jQuery == 'undefined') {
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = '//Libraries/ThirdParty/Jquery/1.10.2.min.js';
jqTag.onload = myJQueryCode;
headTag.appendChild(jqTag);
}
console.log(window.jQuery); // Ar jau yra užkrautas jQuery
if ('undefined' !== typeof window.jQuery) {
console.log(window.jQuery("#Tomas")); // Ar jau yra inicializuotas div'as su ID "Tomas" (wery bad approach)
var main = function () {
var t = $("#Tomas").offset().top;
$(document).scroll(function () {
if ($(this).scrollTop() > t)
{
$("#Tomas")
.css('position', 'fixed') //we change the position to fixed
.css('top', 0); // and the top to zero
} else {
$("#Tomas")
.css('position', 'static') //we change the position to fixed
.css('top', 0); // and the top to zero
}
});
}
$(document).ready(main);
}
正如评论中提到的Sirko,您已经引用了一些回调myJQueryCode
我只举一个实现的例子:
var bbimagebannerfile = "/300x250.jpg";
document.write("<a href='"%%__REDIRECT%%'" target='"_blank'"><img src='"" +
bbimagebannerfile + "'" border='"0'" /></a>");
var onJqueryLoad = function (flag) {
if ('undefined' !== typeof window.jQuery) {
console.log(window.jQuery("#Tomas")); // Ar jau yra inicializuotas div'as su ID "Tomas" (wery bad approach)
var main = function () {
var t = $("#Tomas").offset().top;
$(document).scroll(function () {
if ($(this).scrollTop() > t) {
$("#Tomas")
.css('position', 'fixed') //we change the position to fixed
.css('top', 0); // and the top to zero
} else {
$("#Tomas")
.css('position', 'static') //we change the position to fixed
.css('top', 0); // and the top to zero
}
});
if ('function' === typeof myJQueryCode && !flag) {
myJQueryCode();
}
}
$(document).ready(main);
}
}
if (typeof jQuery == 'undefined') {
var headTag = document.getElementsByTagName("head")[0];
var jqTag = document.createElement('script');
jqTag.type = 'text/javascript';
jqTag.src = '//Libraries/ThirdParty/Jquery/1.10.2.min.js';
jqTag.onload = onJqueryLoad;
headTag.appendChild(jqTag);
}
onJqueryLoad(true);
您还可以在MDN 上查看关于HTMLScriptElement的文章
相关文章:
- jQuery is not loaded
- AngularJS JSON not arriving php
- $rootScope not working
- reactRedux is not defined
- jQuery document.ready not working
- Javascript/Jquery Blob not showing Chrome PDF
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- Javascript getElementsByTagName not working?
- jQuery's trim()的前缀为not运算符
- Javascript - element.childNodes does not see an append.newch
- SemanticUI模态not onDeny/onApprove事件未激发
- WebkitTransform not fluent
- JQuery.val( ) not working
- Tomcat websocket is not working
- :not选择器不适用于ul类-备选方案
- Glyphicon Bootstrap v3 Not loaded
- Dojo dijit.form.button not loaded
- Laravel 5.1 - Javascript not loaded
- Drupal : Flowplayer API not loaded