【问题标题】:Chrome Developer Tool Console does not like Jquery functionsChrome 开发者工具控制台不喜欢 Jquery 功能
【发布时间】:2016-08-29 23:41:36
【问题描述】:

我不确定我做错了什么,但是当我尝试做类似的事情时在我的应用程序中

$('#root').text();

我明白了

VM269:1 Uncaught TypeError: Cannot read property 'val' of null(…)

我不知道为什么我引用 jquery

<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
    <!--materialize does not understand jquery if I use it as import-->
</head>
<body>
    <div id="root"></div>
    <script src="bundle.js"></script>
</body>
</html>

我正在使用 reactjs,但我认为这不应该是一个问题,而且当我执行相同的命令时,我对 firefox 中的 firebug 没有任何问题。

编辑

我的错误$('#test') 是呈现为“根”div 但同样的问题。所以我刚刚更新了我的查询来做$('#root').text()

但是执行$('#root') 可以找到元素,就像我在萤火虫中所说的,一切正常。

【问题讨论】:

  • 在控制台中,你可以使用document.querySelector('#test')访问元素吗?

标签: javascript jquery google-chrome


【解决方案1】:

您正试图从 id='test' 的标签中获取值,而您的 HTMl 中没有。 如果您使用过$('#root').val(),它会起作用。

Helpful selector link

【讨论】:

    【解决方案2】:

    我相信你想要 id="test" 的值。但是,我在您包含的 html 文件中没有看到 id="test"。此外,您还可以尝试 $('#test').text() 来抓取 html 文本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      • 1970-01-01
      • 2016-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多