<!DOCTYPE html><html><head>??? <meta charset="UTF-8">??? <title>onblur和onfocus</title>??? <style type="text/css">??????? .red{??? ??border:1px solid red;??? ?}??? </style></head><body>?姓名:<input type="text"> <span></span>?<script type="text/javascript">??// 補(bǔ)充代碼??window.onload()=function()??{????? var name=document.getElementsByTagName("input")[0];????? var word=document.getElementsByTagName("span")[0];????? name.onfocus=function()????? {????????? if(this.value="")????????? {?????????? this.innerHTML="請輸入你的名字";????????? }????????? ????? }????? word.onblur=function()????? {????????? if(this.value=="")????????? {????????????? this.innerHTML="用戶名不能為空";????????????? this.className="red";????????? }????????? else????????? {????????????? this.innerHTML="";????????? }????? }??}?</script></body></html>
這個怎么產(chǎn)生的效果不對呢
qq_庸人_13
2018-07-30 18:04:10