封闭了一段我的代码。 我希望实现最简单的身份验证机制。 有两个输入字段,用户和密码。 点击发送按钮时,验证()函数被调用时,它检查用户名和密码是否均为“管理员”,如果它拥有然后它显示isCorrect DIV和isWrong否则为。JQuery切换()和自动刷新/渲染
谢谢!
的test.html
<html>
<head>
<link rel="stylesheet" type="text/css" href="test.css"/>
<script src="jquery-1.7.js"></script>
<script src="test.js"></script>
</head>
<body>
<form class="header">
Username: <input type="textbox" tabindex="1" id="username"/>
Password: <input type="password" tabindex="2" id="password"/>
<input type="submit" value="Send" tabindex="3" id="send" onclick="verify()"/>
</form>
<div id="isCorrect">correct!</div>
<div id="isWrong">wrong!</div>
</body>
</html>
test.css
#isCorrect { display: none; }
#isWrong { display: none; }
test.js
function verify() {
var username = $("#username").val();
var password = $("#password").val();
if (username == "admin" && password == "admin")
$("#isCorrect").toggle();
else
$("#isWrong").toggle();
}
你的问题在哪里? – ManseUK
请不要使用此方法进行身份验证,它根本不安全,用户名和密码将在页面的源代码中可见! – Dunhamzzz
目标已经实现,但不能被注意到,因为看起来页面以某种方式被刷新到之前的状态。 – MrIzik