最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught ReferenceError: (function) is not defined - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question asked Jul 17, 2012 at 5:38 fiacobellifiacobelli 1,9905 gold badges24 silver badges31 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 6

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

So, basically I changed the line that said

<script language="text/javascript">

to

<script type="text/javascript">

and it all worked.

Change <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>

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>

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.

发布评论

评论列表(0)

  1. 暂无评论