2011-11-28 89 views
3

这里是我的代码:如何解决“Microsoft JScript运行错误:[方法名称]未定义”

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

我dont't知道为什么,因为我真的定义这个方法。 我怎样才能解决这个问题?

非常感谢。

回答

3

看起来像jquery的,除非你把一个标签来关闭它没有正确closig脚本标签,这使得这些对象无法读取,它给你的错误。下面

代码,希望这有助于。

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

非常感谢你,它确实工作得很好! 但是为什么?我记得人们告诉我脚本应该用'/>'关闭。在我的脑海里...... –

+0

并不清楚你猜对了杰弗里,我不是很确定,为什么是这样的情况,但是当你的Runat =服务器,它搞砸了开启/关闭支架。但是,如果你明确地设置它们,它会正确呈现。 – MatthewJ

相关问题