在initial.html 结尾处 导入script.js 想在script.js写jquery代码,用博客里的方法添加,但是最终没有成功导入jquery库(没有报路径错误)




在initial.html 结尾处 导入script.js 想在script.js写jquery代码,用博客里的方法添加,但是最终没有成功导入jquery库(没有报路径错误)




直接在js中引入jQuery,需等它加载完成之后才能调用它的方法,所以你需要在 window.onload 中进行开发
//引入jQuery
var script=document.createElement("script");
script.type="text/javascript";
script.src="js/jquery-3.6.0.min.js";
document.getElementsByTagName('head')[0].appendChild(script)
//使用jQuery
window.onload = function(){
console.log($);
}