本文實例講述了js實現(xiàn)鼠標點擊文本框自動選中內(nèi)容的方法。分享給大家供大家參考。具體如下:
這里使用JS實現(xiàn)鼠標點擊時自動選中文本框文本的效果,相信許多朋友都遇到這種功能的,就是當我們點擊文本框的時候,文本框中默認的文字會被全部選中,這樣當你輸入的時候不用再去選擇,省去了一些麻煩,提高了輸入效率,用戶肯定會喜歡這功能,那么實現(xiàn)的方法是怎么樣呢?通過本代碼你就搞明白了。
先來看看運行效果截圖:

在線演示地址如下:
http://demo.VeVB.COm/js/2015/js-mouse-click-pitch-style-codes/
具體代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>自動選擇文本框/編輯框中的文字</title><script type="text/javascript">function Myselect_txt(){ if (document.form1.title.focus){ document.form1.title.select();}}function Myselect_txtarea(){ if (document.form1.content.focus){ document.form1.content.select();}}</script></head><body style="font-size:12px"><table width="443" height="97" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#f9f9f9"> <form name="form1"> <tr bgcolor="#214994"> <td height="25" colspan="2"><div align="center"><font color="#FFFFFF">新聞信息修改</font></div></td> </tr> <tr> <td width="80" height="28"><div align="right"><font color="#214994">新聞標題:</font></div></td> <td width="363"><input name="title" type="text" size="50" value="今日新聞頭條" onClick="Myselect_txt()"></td> </tr> <tr> <td height="20"><div align="right"><font color="#214994">新聞內(nèi)容:</font></div></td> <td rowspan="2"><textarea name="content" cols="50" rows="6" onClick="Myselect_txtarea()">今日,據(jù)相關方面報道,...</textarea></td> </tr> <tr> <td height="10"> </td> </tr> <tr> <td height="32" colspan="2"> <div align="center"> <input name="add" type="submit" id="add" value="添加"> <input name="Submit" type="reset" value="重置"> </div></td> </tr> </form></table></body></html>希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答