javascript - requirejs加載報(bào)錯(cuò)問題?
問題描述
1、使用requirejs寫了個(gè)demo.html,第一次加載頁面時(shí)能夠正常顯示,隨后刷新頁面就開始報(bào)錯(cuò),雖然頁面還是正常顯示,但是我不理解為什么會(huì)這樣。2、我的另一個(gè)999.html文件(跟demo.html在同級(jí)目錄下,但是頁面內(nèi)容比較多,其余和1中的html沒有太大區(qū)別)一直報(bào)錯(cuò),要么顯示require is not define要么顯示Script error for 'jquery'或$ is not defined,請(qǐng)問這是為什么,應(yīng)該怎么改?
以下是文件目錄:
代碼如下:
demo.html:
<!DOCTYPE html><html> <head><meta charset='UTF-8'><title></title><script src='http://www.aoyou183.cn/wenda/resource/require.js'></script><script src='http://www.aoyou183.cn/wenda/resource/main.js'></script> </head> <body><script type='text/javascript'> require([’jquery’,’weui’],function($){$(’body’).css(’background’,’red’); });</script> </body></html>
main.js:
require.config({ baseUrl:’resource/app’, paths:{’jquery’:’../lib/jquery-3.2.0.min’,’zepto’:’../lib/zepto.min’,’css’:’../lib/css.min’,’weui’:’../lib/jquery-weui.min’,’cookie’:’../lib/jquery.cookie’,’swiper’:’../lib/swiper’ }});
報(bào)錯(cuò)信息:
<!DOCTYPE html>
<html>
<head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no' /> <title></title> <link rel='stylesheet' type='text/css' href='http://www.aoyou183.cn/wenda/resource/css/weui.css' /> <link rel='stylesheet' type='text/css' href='http://www.aoyou183.cn/wenda/resource/css/jquery-weui.min.css' /> <link rel='stylesheet' type='text/css' href='http://www.aoyou183.cn/wenda/resource/css/index.css' /> <link rel='stylesheet' type='text/css' href='http://www.aoyou183.cn/wenda/resource/css/login.css'/> <link rel='shortcut icon' href='http://www.aoyou183.cn/wenda/resource/font/cake.ico' /> <script src='http://www.aoyou183.cn/wenda/resource/require.js' data-main = 'resource/main' defer async='true'></script></head><body ontouchstart> <!--login section--> <p style='height: auto;'><p class='beforeLogin'> <header><p class='head-bg'></p><p class='touxiang'> <img src='http://www.aoyou183.cn/wenda/img/head/0.png' /></p> </header> <!--登錄--> <section id='login'><form action='login.php' method='post' id='loginForm'> <input type='number' value='' placeholder='請(qǐng)輸入手機(jī)號(hào)' name='user' maxlength='11' /> <input type='password' value='' placeholder='請(qǐng)輸入密碼(6-16位)' name='psw' maxlength='16' /> <button type='submit' id='loginBut'>登錄</button></form><span>沒有賬號(hào)?<a href='http://www.aoyou183.cn/wenda/4035.html#regis'>注冊</a></span><br /><span><a href='http://www.aoyou183.cn/wenda/4035.html#forget'>忘記密碼?</a></span> </section> <!--注冊--> <section id='regis'><form id='checkphone'> <input type='hidden' name='forwhat' value='forcheck' /> <input type='number' value='' placeholder='請(qǐng)輸入手機(jī)號(hào)' name='user' maxlength='11' /> <button type='button' style='color: #fff;background: orange;'>點(diǎn)擊發(fā)送<br />驗(yàn)證碼</button></form><form action='register.php' method='post' id='regisForm'> <input type='hidden' name='forwhat' value='forrig' /> <input type='number' value='' placeholder='請(qǐng)輸入驗(yàn)證碼' name='validate' /> <input type='password' value='' placeholder='設(shè)置密碼(6-16位)' name='psw' maxlength='16' /> <input type='password' value='' placeholder='重新輸入密碼' name='pswcheck' /> <button type='submit' id='regisBut'>注冊</button></form><span>已有賬號(hào)?<a href='http://www.aoyou183.cn/wenda/4035.html#login'>登錄</a></span><br /><span><a href='http://www.aoyou183.cn/wenda/4035.html#forget'>忘記密碼?</a></span> </section> <!--忘記密碼--> <section id='forget'><form id='check4forget'> <input type='hidden' name='forwhat' value='forcheck' /> <input type='number' name='findphone' value='' placeholder='請(qǐng)輸入注冊的手機(jī)號(hào)' maxlength='11'/> <button type='button' id='but2'>點(diǎn)擊發(fā)送<br />驗(yàn)證碼</button></form><form action='validatePhone.php' method='post' id='forgetForm'> <input type='hidden' name='forwhat' value='forreset' /> <input type='number' value='' placeholder='請(qǐng)輸入驗(yàn)證碼' name='validate' /> <input type='password' value='' placeholder='重新設(shè)置密碼(6-16位)' name='psw-forget' maxlength='16' /> <input type='password' value='' placeholder='重新輸入密碼' maxlength='16'/> <button type='submit' id='reset'>重置密碼</button></form><span>已有賬號(hào)?<a href='http://www.aoyou183.cn/wenda/4035.html#login'>登錄</a></span><br /><span>沒有賬號(hào)?<a href='http://www.aoyou183.cn/wenda/4035.html#regis'>注冊</a></span> </section></p><p class='alreadyLogin'> <header><p class='head-bg'> <h3></h3></p><p class='touxiang'> <img src='http://www.aoyou183.cn/wenda/4035.html' /></p> </header> <section><p style='margin-top: 60px;'> <a href='http://www.aoyou183.cn/wenda/4035.html#' class='weui-cell weui-cell_access'><p class='weui-cell__bd'> <p>我的收藏</p></p> </a> <a href='javascript:;' class='weui-cell weui-cell_access kt-exit'><p class='weui-cell__bd'> <p style='color:red;'>退出登錄</p></p> </a></p> </section></p> </p><script type='text/javascript'> require([’jquery’,’weui’],function($){ });</script></body></html>
報(bào)錯(cuò)信息:
問題解答
回答1:手動(dòng)聲明依賴
require.config({ baseUrl:’resource/app’, paths:{’jquery’:’../lib/jquery-3.2.0.min’,’zepto’:’../lib/zepto.min’,’css’:’../lib/css.min’,’weui’:’../lib/jquery-weui.min’,’cookie’:’../lib/jquery.cookie’,’swiper’:’../lib/swiper’ }, shim: {weui: {deps: ['jquery']}}});
以及 999.html 中加載 require.js 時(shí)不要 defer 和 async
相關(guān)文章:
1. [python2]local variable referenced before assignment問題2. thinkPHP5中獲取數(shù)據(jù)庫數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙3. mysql主從 - 請(qǐng)教下mysql 主動(dòng)-被動(dòng)模式的雙主配置 和 主從配置在應(yīng)用上有什么區(qū)別?4. 求救一下,用新版的phpstudy,數(shù)據(jù)庫過段時(shí)間會(huì)消失是什么情況?5. linux運(yùn)維 - python遠(yuǎn)程控制windows如何實(shí)現(xiàn)6. python小白,關(guān)于函數(shù)問題7. django - Python error: [Errno 99] Cannot assign requested address8. python小白 關(guān)于類里面的方法獲取變量失敗的問題9. Python2中code.co_kwonlyargcount的等效寫法10. android - 請(qǐng)問一下 類似QQ音樂底部播放 在每個(gè)頁面都顯示 是怎么做的?
