undefined - 如何解决 "Microsoft JScript runtime error: ' [方法名]' is undefined"

标签 undefined

这是我的代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js" />
    <script type="text/javascript" language="javascript">
        var count = 0;
        function Start()
        {
            setInterval("ReadNotification()", 1000);
        }
        function ReadNotification()
        {
            alert(++count);
        }
    </script>
</head>
<body onload="return Start();">
</body>
</html>

我刚刚运行这段代码并收到一个经典错误:

Microsoft JScript runtime error: 'Start' is undefined

不知道为什么,因为我真的定义了这个方法。 我该如何解决这个问题?

非常感谢。

最佳答案

看起来 jquery 的脚本标签没有正确关闭,除非你放置一个标签来关闭它,这会导致这些对象不可读,从而给你错误。

下面的代码,希望对您有所帮助。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js">
    </script>
    <script>
        var count = 0;
        function Start()
        {
            setInterval("ReadNotification()", 5000);
        };
        function ReadNotification()
        {
            alert(++count);
        };
    </script>
</head>
<body onload="return Start();">

</body>
</html>

关于undefined - 如何解决 "Microsoft JScript runtime error: ' [方法名]' is undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8303850/

相关文章:

node.js - Express.js req.session 在路由中未定义

node.js - 在nodejs中运行Neo4j查询返回 "undefined"

javascript - DOM 未定义错误

c++ - 在 linux 上链接 FMOD 库时 undefined reference

javascript - 从数组中获取随机数,不重复(使用计时器)

javascript - react : How do you write id to have dynamic axios requests

Javascript未定义函数..但它确实已定义

javascript - 如何使用返回http promise的angular 2服务

javascript - 动态对象定义

Javascript document.getElement insideHTML 未定义