用JavaScript寫輸入框的校驗(yàn)
//Script ? ? ? ?function cheack(){ ? ? ? ? ? ?var kong = ''//獲取值不能放外面,不然一直為空
? ? ? ? ? ? ? ?kong = document.getElementById('name').value.trim()//trim是去掉空格
? ? ? ? ? ?var password =''
? ? ? ? ? ? ? ?password = document.getElementById('pass').value.trim() ? ? ? ? ? ?
? ? ? ? ? ?if(kong<6 || kong>20){
? ? ? ? ? ? ? ?alert('你別找事啊')
? ? ? ? ? ?} ? ? ? ? ? ?if(kong.charAt(1)){
? ? ? ? ? ? ? ?alert('第一位不能為數(shù)字')
? ? ? ? ? ?} ? ? ? ? ? ?if(!password){
? ? ? ? ? ? ? ?alert('密碼不能為空')
? ? ? ? ? ?}
? ? ? ? ? ?
? ? ? ?}//HTML
<input type="text" placeholder="請(qǐng)輸入用戶名" ?id="name" onfocus="heihei()">
? ?<input type="password" placeholder="請(qǐng)輸入密碼" id="pass">
? ?<button onclick="cheack()">登錄</button>
來(lái)源:https://www.dianjilingqu.com/471469.html