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

网络编程 发布日期:2024/10/6 浏览次数:1

正在浏览:JS实现选择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程序设计有所帮助。

Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。