0

嗨,这里又是同样的问题 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 谢谢

4

1 回答 1

0

这是一个范围问题:

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

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

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

<button type="submit"  id="btnLogin" data-theme="b">
    Submit</button>
于 2013-03-01T13:05:39.793 回答