microsoft jscript运行时错误:函数未定义

时间:2013-03-01 12:59:12

标签: jquery asp.net ajax

嗨再来这里是同样的问题js错误函数未定义(onForgotPasswordClick未定义),我不知道它现在是简单的普通页面(没有母版页),请帮忙

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

1 个答案:

答案 0 :(得分:0)

这是范围问题:

onForgotPasswordClick$("#main-page").on('pageinit')上运行的匿名函数内定义,但在该函数之外(在HTML中)调用。这是不可能的。但是,没有什么能阻止你在该范围内调用它。在页面顶部的script元素中添加以下行:

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

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

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