Jquery .each()不使用chrome

时间:2013-10-17 09:35:33

标签: javascript jquery google-chrome autogrow

我正在使用Jquery Elastic。它适用于Firefox,但在chrome中失败。我只有一个textarea我正在使用它。

HTML:

<textarea id = "tarea">Lorem Ipsum</textarea>

将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'事件。它现在有效。我无法理解为什么。

1 个答案:

答案 0 :(得分:0)

  

注意:对于Chrome浏览器,不要期望$总是JQuery

您可以将$放入控制台以检查其是否返回ƒ $(selector, [startNode]) { [Command Line API] },如果是,则表示未为JQuery定义$。

这是一个好消息,您可以通过以下方式尝试:

  1. 解决使用$的冲突,将其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/


  1. 在Chrome中使用.js文件,然后调试JavaScript文件。

引用: Chrome DevTools Snippets

  1. 此外,对于某些特定版本的Chrome,UI中还有一个选项可以设置page context 可能已删除为最新版本!)。

img

引用:

https://stackoverflow.com/a/8581276/6075331https://stackoverflow.com/a/15197993/6075331