简体   繁体   English

javascript功能无法执行

[英]javascript function doesn't execute

Hi,I have simple login form, where fields are validated by javascript. 嗨,我有一个简单的登录表格,其中的字段由javascript验证。 I don't now why the below code is not working. 我现在不理解以下代码为何不起作用。

my html and js code: 我的html和js代码:

<head>
        <script type="text/javascript">
        function handleLogin() {

            var u = $("#username").val();
            var p = $("#password").val();

            if(u=="a" && p=="a")
                {

                window.location="/Site/site.html";
                }
            else
                {
                alert("Fail");
                }

        }
        </script>

</head> 
<li dojoType="dojox.mobile.ListItem"> 
            <input dojoType="dojox.mobile.app.TextBox" placeHolder="username" type="text" id="username" name="username" />
        </li>
        <li dojoType="dojox.mobile.ListItem">
            <input dojoType="dojox.mobile.app.TextBox" placeHolder="password" type="password" id="password" name="password" />
        </li>
        <li dojoType="dojox.mobile.ListItem">
            <input dojoType="dojox.mobile.Button" onclick="handleLogin()" type="button" id="submit" name="submit" value="Login"/> 
        </li>

When I click on the submit button nothings happening. 当我单击提交按钮时,没有任何反应。

Thanks 谢谢

You didn't load the jQuery library. 您没有加载jQuery库。 But you can do without it: 但是您可以没有它:

var u = document.getElementById('username').value,
p = document.getElementById('password').value;

Changing the page is done with location.href instead of window.location : 更改页面是通过location.href而不是window.location

location.href = '/Site/site.html';

尝试导入

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM