焦点的补充

获得焦点的方法

1 function getfocus(){
2     document.getElementById("ok").focus();
3 }
4 window.onload=getfocus;

 

判断是否获得了焦点

1     if(document.activeElement.id="ok"){
2         alert("获得焦点");
3     }
4     else
5         alert("没有获得焦点");

判断哪一个元素获得焦点的方法

1 var st = document.activeElement.id;
2     alert(st);


innerHTML的用法

1 <div id="ak"></div>
2 function interHtml(){
3     var st="老鼠爱大米";
4     ak.innerHTML=st;
5 }

 

配合焦点的密码验证框

1 <form name="form2" action="" method="post">
2         <input type="text" name="ad" id="ol"> <input type="text"
3             name="bd" id="al"> <input type="button" name="check"
4             value="测试" onclick="checkout()">
5     </form>
 1 function checkout() {
 2     if (document.form2.ol.value.length == 0) {
 3         alert("内容不能为空");
 4         document.getElementById("ol").focus();
 5         return false;
 6     }
 7     if (document.form2.al.value.length == 0) {
 8         alert("内容不能为空");
 9         document.getElementById("al").focus();
10         return false;
11     }
12     if (document.form2.ol.value != document.form2.al.value) {
13         alert("输入的内容不一致");
14         document.form2.al.value = "";
15         document.getElementById("al").focus();
16         return false;
17     }
18     alert("登陆成功");
19 }

 

 

 

 

 

posted @ 2013-08-30 18:10  最是那一杯红酒  阅读(147)  评论(0编辑  收藏  举报