gpt4 book ai didi

JavaScript 同步

转载 作者:行者123 更新时间:2023-11-30 13:14:05 31 4
gpt4 key购买 nike

我不知道如何同步下一个代码:

javascript: (function() {
var s2 = document.createElement('script');
s2.src = 'http://192.168.0.100/jquery.js';
document.body.appendChild(s2);
s = document.createElement('link');
s.rel = "stylesheet";
s.href = "http://192.168.0.100/1.css";
s.type = "text/css";
document.body.appendChild(s);
})();
//var startTime = new Date().getTime();
//while (new Date().getTime() < startTime + 1000);
$(document).ready(function(){
b="c:\\1.txt";
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile(b, true);
f1.WriteLine("Testing") ;
document.writeln("File " + b + " is created.");
});

当我第一次运行这个脚本时,我得到一个错误 SCRIPT5009: '$' is undefined。我认为这是因为 jQuery 库尚未加载。当我在出现错误后尝试运行相同的脚本时 - 它的行为是正确的。对于同步,我尝试使用上面列表中注释的代码。是作品(不总是)。但我知道这不是严格的同步(它取决于具体情况)。如何使用更智能的同步?

最佳答案

(function($){
//use $ now

$(function(){
//dom ready
});

})(jQuery);

请务必在 jquery 库下方的页脚中加载此库。

关于JavaScript 同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12762696/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com