這篇文章主要介紹了js實(shí)現(xiàn)文本框選中的方法,涉及javascript中select()方法的使用技巧,需要的朋友可以參考下
本文實(shí)例講述了js實(shí)現(xiàn)文本框選中的方法。分享給大家供大家參考。具體如下:
這段javascript代碼可解決文本框獲得焦點(diǎn),即使得文本框的內(nèi)容被選中。
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>select文件</title>
- <script language="javascript" type="text/javascript">
- function getFocus()
- {
- document.getElementById("test").select();
- }
- </script>
- </head>
- <body>
- <form id="f1">
- <input type="text" id="test" name="test" value="你好嗎?"
- onfocus="getFocus();"/>
- </form>
- </body>
- </html>
希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選