js单击自动选择文本

Posted on 2016-08-17 16:39  听风吹来的种子  阅读(305)  评论(0编辑  收藏  举报
 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 2 <html>
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
 5 <title>自动选择文本框/编辑框中的文字</title>
 6 <script type="text/javascript">
 7   function Myselect_txt(){
 8     if (document.form1.title.focus){
 9       document.form1.title.select();
10 
11     }
12   }
13   function Myselect_txtarea(){
14     if (document.form1.content.focus){
15       document.form1.content.select();
16 
17     }
18   }
19 </script>
20 </head>
21 <body style="font-size:12px">
22   <table width="443" height="97" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f9f9f9">
23     <form name="form1">
24       <tr bgcolor="#214994">
25         <td height="25" colspan="2"><div align="center"><font color="#FFFFFF">新闻信息修改</font></div></td>
26       </tr>
27       <tr>
28         <td width="80" height="28"><div align="right"><font color="#214994">新闻标题:</font></div></td>
29         <td width="363"><input name="title" type="text" size="50" value="今日新闻头条" onClick="Myselect_txt()"></td>
30       </tr>
31       <tr>
32         <td height="20"><div align="right"><font color="#214994">新闻内容:</font></div></td>
33         <td rowspan="2"><textarea name="content" cols="50" rows="6" onClick="Myselect_txtarea()">今日,据相关方面报道,...</textarea></td>
34       </tr>
35       <tr>
36          <td height="10">&nbsp;</td>
37       </tr>
38       <tr>
39          <td height="32" colspan="2">
40            <div align="center">
41               <input name="add" type="submit" id="add" value="添加">&nbsp;
42               <input name="Submit" type="reset" value="重置">
43             </div>
44 
45         </td>
46       </tr>
47     </form>
48   </table>
49 </body>
50 </html>