這篇文章主要介紹了JS實現選擇TextArea內文本的方法,涉及javascript針對頁面TextArea元素焦點設置及文本獲取的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了JS實現選擇TextArea內文本的方法。分享給大家供大家參考。具體實現方法如下:
- <script type="text/javascript">
- function select_field(id){
- document.getElementById(id).focus();
- document.getElementById(id).select();
- }
- function init(){
- select_field('text1');
- }
- onload=init;
- </script>
- <form>
- This field gets selected onload:<br/>
- <input type="text" name="text1" id="text1" value="some text" />
- <br/>
- <textarea name="textarea1" id="textarea1" rows="9" cols="50" wrap="off">Some long
- content in here.
- abcd efgh abcd efgh abcd efgh
- abcd efgh abcd efgh abcd efgh
- abcd efgh abcd efgh abcd efgh
- </textarea>
- <br/>
- <input type="button" value="Select text" onclick="select_field('textarea1')">
- </form>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答
圖片精選