本文介绍了如何解决“Microsoft JScript 运行时错误:'[Method Name]' 未定义"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

<%@ 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>

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

I just run this code and received a classic error:

Microsoft JScript runtime error: 'Start' is undefined

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

I dont't know why, because I really defined this method.How can I solve this problem ?

非常感谢.

推荐答案

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

Looks like the script tag for jquery is not closig properly unless you put a tag to close it, which renders those objects not readable, which gives you the error.

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

Code below, hope this helps.

<%@ 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>

这篇关于如何解决“Microsoft JScript 运行时错误:'[Method Name]' 未定义"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 19:25