Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在某些网站上使用jQuery函数会导致未捕获的类型错误_Javascript_Jquery_Browser Console - Fatal编程技术网

Javascript 在某些网站上使用jQuery函数会导致未捕获的类型错误

Javascript 在某些网站上使用jQuery函数会导致未捕获的类型错误,javascript,jquery,browser-console,Javascript,Jquery,Browser Console,我通过在Chrome控制台中编写一些代码来学习jQuery,例如向DOM元素添加id,然后执行jQuery函数 例如,在一些网站上,我得到了未捕获的TypeError,而在其他网站上,我没有。以下是一个例子: DOM修改: <input id="test" aria-label="Szukaj w Google" name="btnK" type="submit" jsaction="sf.chk"> 错误: VM598:1 Uncaught TypeError: $(...).h

我通过在Chrome控制台中编写一些代码来学习jQuery,例如向DOM元素添加
id
,然后执行jQuery函数

例如,在一些网站上,我得到了
未捕获的TypeError
,而在其他网站上,我没有。以下是一个例子:

DOM修改:

<input id="test" aria-label="Szukaj w Google" name="btnK" type="submit" jsaction="sf.chk">
错误:

VM598:1 Uncaught TypeError: $(...).hide is not a function
at <anonymous>:1:12
VM598:1未捕获类型错误:$(…)。hide不是函数

(在)工作。原因是什么?

互联网上的许多网站都没有加载jQuery。这就是为什么会收到错误消息
uncaughttypeerror:$(…)。hide不是一个函数
,因为实际上
$
不是jQuery,而是另一个函数、对象,或者它只是未定义而已

虽然您可以在许多网站上找到loaded,但有一些公司/项目/网站不使用jQuery,或者在
$
符号下使用a或其他东西,或者根本不使用


在网站上,默认情况下,

  • $
    符号是的别名
  • $$
    符号是的别名
如果该特定网站没有使用其他实现(例如自定义函数、库、jQuery等)覆盖这些变量

归功于



如果您需要在一个网站上使用jQuery(例如,出于开发目的,),而该网站上没有jQuery,.

,但当我执行例如$(“#test”).value=“newValue”时,它可以在google上工作,我可以在搜索按钮上更改字符串,因此我假设jQuery是加载到google上的,
$
下可能有一个自定义库,或者它是一个定制的jQuery。如果您使用Chrome,您可以在“网络”和“源”选项卡下查看它,在“
$
符号”下他们真正使用的代码是什么。@SigGP通常使用
$
作为查找元素的函数的简称。但它并不总是jQuery。当控制台中没有另外定义
$
时。
VM598:1 Uncaught TypeError: $(...).hide is not a function
at <anonymous>:1:12