Microsoft JScript中的运行时错误:函数是未定义

问题描述:

喜在这里再次被同样的问题JS错误函数未定义(onForgotPasswordClick是不确定的),我不知道现在是简单的纯页面上(不包括母版页),请帮助Microsoft JScript中的运行时错误:函数是未定义

   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.css" /> 
    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.3.0-rc.1/jquery.mobile-1.3.0-rc.1.min.js">  </script> 

    <link href="Scripts/Style.css" rel="stylesheet" type="text/css" /> 
     <script type="text/javascript"> 
      $("#main-page").on('pageinit', function (event) { 
       function onForgotPasswordClick() { 
         WebApplication.Services.ForgetPassword.HelloWorld(onMethodSucceeded, onMethodFailed); 
       } 

       function onMethodSucceeded(results, args) { 
        alert(results); 
       } 

       function onMethodFailed(error) { 
       } 
      }); 

    </script> 
</head> 
<body> 

    <form id="Form1" runat="server"> 

    <asp:ScriptManager ID="ScriptManager" runat="server"> 

     <Services> 
      <asp:ServiceReference Path="~/ForgetPassword.asmx" /> 
     </Services> 
     </asp:ScriptManager> 

    <div data-role="page" id="main-page"> 
     <div data-role="header" data-theme="b"> 
     <a href="/" class="ui-btn-right">Cancel</a> <h1> 
       Forgot Password</h1> 
     </div> 
     <div data-role="content" > 


      <fieldset data-role="fieldcontain" class="ui-hide-label" > 

         <legend> 
Username:</legend> 
     <input type="text" name="txtUsername" id="txtUsername" value=""  placeholder="Username" /> 

         <legend> 
          Email:</legend> 
         <input type="email" name="txtemail" id="txtemail" value="" placeholder="Email" /> 

         <button type="submit" id="btnLogin" data-theme="b" onclick="onForgotPasswordClick()"> 
          Submit</button> 
        <hr /> 

      </fieldset> 
       <div style="display:none" id="msg"> 

      </div> 
     </div> 


     <div data-role="footer" data-theme="b"> 
     <h4>&copy; 2013 All rights reserved.</h4> 
     </div> 
    </div> 

    </form> 


</body> 
</html> 

这里的类似的帖子... microsoft jscript runtime error:test is undefined 感谢

这是一个范围问题:

onForgotPasswordClick的是,在0运行匿名函数中定义,但它在该函数之外调用(在HTML中)。这是不可能的。但是,没有什么能阻止你在该范围内调用它。添加脚本元素下面一行在页面的顶部:

$(document).on('click', '#btnLogin', onForgotPasswordClick); 

...然后从按钮删除onclick处理程序:

<button type="submit" id="btnLogin" data-theme="b"> 
    Submit</button> 
+0

谢谢你,我会尝试这些变化.. .. – Fluminda 2013-03-01 13:18:34