首页 > 语言 > JavaScript > 正文

JS实现选择TextArea内文本的方法

2024-05-06 16:24:17
字体:
来源:转载
供稿:网友

这篇文章主要介绍了JS实现选择TextArea内文本的方法,涉及javascript针对页面TextArea元素焦点设置及文本获取的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了JS实现选择TextArea内文本的方法。分享给大家供大家参考。具体实现方法如下:

 

 
  1. <script type="text/javascript"
  2. function select_field(id){ 
  3. document.getElementById(id).focus(); 
  4. document.getElementById(id).select(); 
  5. function init(){ 
  6. select_field('text1'); 
  7. onload=init; 
  8. </script> 
  9. <form> 
  10. This field gets selected onload:<br/> 
  11. <input type="text" name="text1" id="text1" value="some text" /> 
  12. <br/> 
  13. <textarea name="textarea1" id="textarea1" rows="9" cols="50" wrap="off">Some long 
  14. content in here. 
  15. abcd efgh abcd efgh abcd efgh 
  16. abcd efgh abcd efgh abcd efgh 
  17. abcd efgh abcd efgh abcd efgh 
  18. </textarea> 
  19. <br/> 
  20. <input type="button" value="Select text" onclick="select_field('textarea1')"
  21. </form> 

希望本文所述对大家的javascript程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选