Javascript 未捕获的 ReferenceError: (function) 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11516586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 06:07:39  来源:igfitidea点击:

Uncaught ReferenceError: (function) is not defined

javascript

提问by fiacobelli

I just think this is useful for people having this problem:

我只是认为这对遇到此问题的人很有用:

I had this code:

我有这个代码:

<html>
<head>
    <link rel="stylesheet" href="example.css" type="text/css"/>
    <title>CSS TESTS</title>
    <script language="text/javascript">
        var move = 0;
    </script>
</head>
<body>
    <input type="text" id="shape" onchange="alert(move);"/>
</body>
</html>

But I couldn't get the alert to work. I would get the Uncaught ReferenceError: move is not defined.

但是我无法让警报起作用。我会得到 Uncaught ReferenceError: move is not defined。

回答by fiacobelli

It turns out that the languageattribute on the script tag did not allow me to specify text/javascriptbut only javascript. The typeattribute allows "text/javascript". That was all and I spent hours trying to find the bug in the javascript code... arg!

事实证明,脚本标签上的语言属性不允许我指定text/javascript而只能指定javascript。该类型属性允许“文/ JavaScript的”。这就是全部,我花了几个小时试图找到 javascript 代码中的错误...... arg!

So, basically I changed the line that said

所以,基本上我改变了说

<script language="text/javascript">

to

<script type="text/javascript">

and it all worked.

这一切都奏效了。

回答by swapnesh

Change <script language="text/javascript">TO <script type="text/javascript">

更改<script language="text/javascript">TO<script type="text/javascript">

Working Code --

工作代码——

<html>
<head>
    <link rel="stylesheet" href="example.css" type="text/css"/>
    <title>CSS TESTS</title>
    <script type="text/javascript">
        var move = 0;
    </script>
</head>
<body>
    <input type="text" id="shape" onchange="alert(move);"/>
</body>
</html>

回答by shershen

or do this, here "move" casted as string

或者这样做,这里“移动”被转换为字符串

<html>
<head>
    <link rel="stylesheet" href="example.css" type="text/css"/>
    <title>CSS TESTS</title>
</head>
<body>
    <input type="text" id="shape" onchange="alert('move');"/>
</body>
</html>

回答by CleanX

Dont forget to include ,

不要忘记包括,

 <script src="jquery-1.xx.x.min.js" type="text/javascript"> </script>

if you are using jquery, xx-x stand for the version you are using.

如果您使用 jquery,xx-x 代表您使用的版本。