HTML DOM select() 方法

定义和用法

select() 方法用于选取文本域中的内容。

语法

  1. textObject.select()

实例

下面的例子可选取文本域中的内容:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function selText()
  5. {
  6. document.getElementById("myText").select()
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <form>
  13. <input size="25" type="text" id="myText" value="A cat played with a ball">
  14. <input type="button" value="Select text" onclick="selText()">
  15. </form>
  16.  
  17. </body>
  18. </html>