生活随笔
收集整理的這篇文章主要介紹了
JavaScript 基础,登录前端验证
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
<script></script>的三種用法:放在<body>中放在<head>中放在外部JS文件中三種輸出數(shù)據(jù)的方式:使用 document.write() 方法將內(nèi)容寫到 HTML 文檔中。使用 window.alert() 彈出警告框。使用 innerHTML 寫入到 HTML 元素。使用 "id" 屬性來(lái)標(biāo)識(shí) HTML 元素。使用 document.getElementById(id) 方法訪問 HTML 元素。用innerHTML 來(lái)獲取或插入元素內(nèi)容。
登錄頁(yè)面準(zhǔn)備:增加錯(cuò)誤提示框。寫好HTML+CSS文件。設(shè)置每個(gè)輸入元素的id定義JavaScript 函數(shù)。驗(yàn)證用戶名6-20位驗(yàn)證密碼6-20位onclick調(diào)用這個(gè)函數(shù)。 <!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>login
</title><link href="../static/css/login.css" rel="stylesheet" type="text/css"><script>function myLogin() {var oUname = document.getElementById("uname");var oError = document.getElementById("error_box1");if(oUname.value.length<6){oError.innerHTML ="用戶名至少六位!"}else if(oUname.value.length>10){oError.innerHTML ="用戶名最多十位!"}var oUpass = document.getElementById("upass");var oError = document.getElementById("error_box2");if( oUpass .value.length<6){oError.innerHTML ="密碼至少六位!"}else if(oUpass .value.length>10){oError.innerHTML ="密碼最多十位!"}}</script>
</head>
<body ><div class="bor"><form id="login" action="" method="post"><h2 align="center"><div id="header"><h3 align="center" >登錄
</h3></div><div class="input_box">username:<input id="uname" type="text" placeholder="請(qǐng)輸入用戶名"></div><div class="input_box">password:<input id="upass" type="password" placeholder="請(qǐng)輸入密碼"></div><div id="error_box1" ><br></div><div id="error_box2" ><br></div><div class="input_box"><button onclick="myLogin()">登錄
</button><button >重置
</button></div></h2></form></div>
</body>
</html> html{font-family: 華文細(xì)黑;}
.bor{position:absolute;top:50%;left:50%;margin-top: -200px;margin-left:-200px;widht:500px;height:300px;}
body{background:url("http://p1.so.qhimgs1.com/bdr/_240_/t010d4fb773a19d42d1.jpg") no-repeat;width:100%;height:auto;overflow:hidden;background-size:100%;
}
#error_box1{color: red;}
#error_box2{color: red;
}
轉(zhuǎn)載于:https://www.cnblogs.com/wk15/p/7739701.html
總結(jié)
以上是生活随笔為你收集整理的JavaScript 基础,登录前端验证的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。