js實現(xiàn)簡單登錄功能的實例代碼
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Login.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function checkuser() {
if($('uname' == "lala") && $('pwd') == "123") {
return true;
}else {
return false;
}
}
function $(id) {
return document.getElementById(id).value;
}
</script>
</head>
<body>
<form action="ok.html">
u:<input type="text" id="uname"/><br>
p:<input type="password" id="pwd"/><br>
<input type="submit" value="登錄" onclick="return checkuser()"/>
</form>
</body>
</html>
這是登錄頁面,只有當(dāng)用戶名為lala,密碼為123時登錄成功。在onclick事件處使用return,是在用戶名和密碼輸入不符時,阻止頁面跳轉(zhuǎn)。登錄成功頁面中,含有等待秒數(shù),代碼為:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ok.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript">
function tiao() {
clearInterval(mytime);
window.open("manage.html","_self");
}
setTimeout("tiao()",5000);
function changeSec() {
//得到myspan值
$('myspan').innerText=$('myspan').innerText-1;
}
function $(id) {
return document.getElementById(id);
}
var mytime = setInterval("changeSec()",1000);
</script>
</head>
<body>
登錄成功,<span id="myspan">5</span>秒后自動跳轉(zhuǎn)到管理頁面
</body>
</html>
關(guān)鍵在幾個函數(shù)的使用,setTimeout("tiao()",5000);函數(shù)是打開頁面,等待5秒,調(diào)用tiao()函數(shù)。setInterval("changeSec()",1000);函數(shù)是每隔1秒調(diào)用一次changeSec()函數(shù)。這樣就完成了簡單的登錄功能。
相關(guān)文章
Ajax局部更新導(dǎo)致JS事件重復(fù)觸發(fā)問題的解決方法
如果頁面中包含一個ajax更新的列表,那么需要小心非動態(tài)更新部分的事件處理,下面以帶有公共工具欄的列表界面為例2014-10-10
javascript正則表達式使用replace()替換手機號的方法
這篇文章主要介紹了javascript正則表達式使用replace()替換手機號的方法,可實現(xiàn)把手機號第4位到第7位替換成****的功能,是非常實用的技巧,需要的朋友可以參考下2015-01-01
javascript轉(zhuǎn)換字符串為dom對象(字符串動態(tài)創(chuàng)建dom)
那么今天的目的就是教大家怎么去實現(xiàn)一個這樣的方法用來把字符串直接轉(zhuǎn)換為標(biāo)準(zhǔn)的dom對象2010-05-05
JavaScript反轉(zhuǎn)數(shù)組常用的4種方法
這篇文章主要給大家介紹了關(guān)于JavaScript反轉(zhuǎn)數(shù)組常用的4種方法,反轉(zhuǎn)數(shù)組可以將數(shù)組中的元素順序顛倒過來,從而達到一些特定的需求,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07
Javascript實現(xiàn)DIV滾動自動滾動到底部的代碼
一個比較特殊的客戶要求,在一個頁面用表格顯示數(shù)據(jù),數(shù)據(jù)量不是很多,不希望使用瀏覽器的滾動條,只能在Div中滾動table中的數(shù)據(jù),但是有個特殊的要求,就是必須將滾動條自動滾動到底部2012-03-03

