1
我已經實現了這個代碼:Modernizr何時加載腳本?
<script>
var mod_PPfix = false;
Modernizr.load({
test: Modernizr.csstransitions && Modernizr.input.required,
nope: ['script1.js', 'script2.js'],
complete: function() {
mod_PPfix = true;
console.log('ppfix');
}
});
</script>
幾行字後,我已經放在這個腳本等
<script>
if (!mod_PPfix) {
$(document).ready(function() {
console.log('this should be seen only if modernizr's tests are true');
});
}
</script>
現在我真的javascript中的菜鳥,但我預計,從上面的代碼只有在modernizr測試結果爲真時才顯示第二個console.log()
。即使測試結果爲負數,仍會記錄第二個日誌。
據我所知,在控制檯第二個console.log()
消息出現在第一個說'ppfix'之前,所以我猜這應該是一種加載時間問題,但我真的不知道爲什麼。我究竟做錯了什麼?
如果它可以幫助我使用jquery作爲庫。
謝謝!
**不要你的意思是,如果(mod_PPfix)?**對不起它的有點曲折我知道,我的意思是「如果modernizr驗證這兩個專長都沒有實現,那麼它會加載我列出的2個腳本並設置爲mod_PPfix = true」。只有在兩者都不支持的情況下,才加載腳本並執行完整的功能。 如果功能結果支持,那麼他什麼也不做,沒有腳本加載,也不會執行完整的功能。 我發佈的代碼與我的意思是否正確? – Gruber
_What你想要在第二