$(document).ready 在2.0版本下的bootstrap会失效

博客指出$(document).ready在Bootstrap 2.0版本下会失效,涉及前端开发中JavaScript与Bootstrap框架的兼容性问题。
如题
(function ($) { // 创建通用脚本加载函数 const loadScript = (url) => { return new Promise((resolve, reject) => { $.getScript(url) .done(resolve) .fail((jqxhr, settings, exception) => { reject(new Error(`脚本加载失败: ${url}`, { cause: exception })); }); }); }; // 页面路由配置 const routeConfig = { "/KuCun2/login.html": [ '/KuCun2/js/main.js', '/KuCun2/js/login.js' ], "/KuCun2/main/Guanli.html": [ '/KuCun2/js/main.js', '/KuCun2/js/guanli.js', '/KuCun2/main/bootstrap-3.3.7-dist/js/FileSaver.js', '/KuCun2/js/table.js' ], "/KuCun2/index.html": [ '/KuCun2/js/main.js', '/KuCun2/js/index.js' ] }; // 带缓存清除的加载函数 async function loadRouteScripts() { const pathName = window.location.pathname; const scripts = routeConfig[pathName] || []; try { // 并行加载所有脚本(带时间戳防缓存) await Promise.all(scripts.map(url => loadScript(`${url}?v=${Date.now()}`) )); // 全部加载完成后执行页面初始化 await initializePageLogic(pathName); } catch (error) { console.log(error) console.error('关键脚本加载失败:', error); showSystemError(); } } // 页面逻辑初始化 async function initializePageLogic(pathName) { switch(pathName) { case '/KuCun2/login.html': // 确保 login.js 的初始化代码已执行 await loginModule.initialize(); break; case '/KuCun2/main/Guanli.html': // 等待表格组件初始化 await MyTableModule.ready(); // 执行原立即调用函数中的逻辑 await fetchAndRenderUserTable(); break; case '/KuCun2/index.html': indexModule.startAnalytics(); break; } } // 错误处理 function showSystemError() { document.body.innerHTML = ` <div class="error-overlay"> <h2>系统初始化失败</h2> <button onclick="location.reload()">重新加载</button> </div> `; } // 启动加载流程 $(document).ready(() => { loadRouteScripts(); }); })(jQuery) 关键脚本加载失败: ReferenceError: indexModule is not defined at initializePageLogic (jsyilai.js:79:14) at loadRouteScripts (jsyilai.js:54:16)
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值