0

我正在使用 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'事件。它现在有效。我不明白为什么。

4

1 回答 1

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 中使用.jsfile 代替,然后调试 JavaScript 文件。

参考: Chrome DevTools Snippets

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

图像.

参考:

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

于 2019-04-26T00:26:12.723 回答