[英]Jquery .each() not working in chrome
我正在使用Jquery Elastic 。 它在Firefox上可以正常使用,但在chrome中無法使用。 我只有一個textarea正在使用。
HTML:
<textarea id = "tarea">Lorem Ipsum</textarea>
使用plugin函數將textarea綁定:
$(document).load(function() { $('#tarea').elastic() ; }) ;
我打開了插件文件,並通過alert
語句找到了在chrome中執行停止的地方:
--- code above this initializing arrays, works fine in both FF and chrome
return this.each( function() {
-- Chrome does not execute anything in the callback
// Elastic only works on textareas
if ( this.type !== 'textarea' ) {
return false;
}
.
.
.
}
--- return ends here , chrome does not execute anything here either.
我已經用Firebug檢查了JS的錯誤,卻一無所獲。 我也有適用於chrome的類似插件,即使該插件也不會報告任何JavaScript錯誤。
更新:
我將對插頭的調用從'load'
事件更改為'ready'
事件。 現在就可以了。 我不明白為什么。
注意:對於Chrome,不要期望$始終是
JQuery
。
您可以將$
放入控制台以檢查它是否返回ƒ $(selector, [startNode]) { [Command Line API] }
,如果是,則表示未為JQuery
定義$。
這是一個好消息,您可以嘗試以下方法:
$
的沖突,讓它成為沒有任何歧義的jQuery
首先,您可以將此代碼段放入
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-3.3.1.min.js"; /* Include any online jquery library you need */
document.getElementsByTagName('head')[0].appendChild(jq);
放入控制台,然后將$.noConflict
放入控制台,如果它未返回undefined
,而是返回ƒ (t){return e.$===w&&(e.$=Kt),t&&e.jQuery===w&&(e.jQuery=Jt),w}
,這意味着現在尚未為JQuery
定義$
。
接下來,您可以繼續輸入您的區域代碼,然后您會發現它現在運行良好。
請參考 : https : //blog.wplauncher.com/run-jquery-in-chrome-console/
.js
文件代替,然后調試JavaScript文件。 page context
( 可能已在最新版本中刪除了此功能!) 。
參考:
https://stackoverflow.com/a/8581276/6075331 , https://stackoverflow.com/a/15197993/6075331
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.