select方法可以将窗口子组件内的文字反白标示起来 主要用于"text"和"textarea"
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>model</title>
6 <script language="javascript">
7 function testSelect(){
8 for(x=0;x<document.forms[0].length;x++){
9 if(document.forms[0][x].value==""){
10 document.forms[0][x].focus();
11 document.forms[0][x].value="必填字段!!";
12 document.forms[0][x].select();
13 return false;
14 }
15 }
16 }
17 </script>
18 </head>
19 <body>
20 <img src="img/d1.gif">
21 <form name="myForm">
22 加入会员请填写数据: <br />
23 姓名:
24 <input type="text" name="userName" />
25 <br />
26 email:
27 <input type="text" name="userEmail" />
28 <br />
29 电话:
30 <input type="text" name="userPhone" />
31 <input type="button" value="发送数据" onclick="testSelect()" />
32 </form>
33 </body>
34 </html>