--- title: GlobalEventHandlers.onselect slug: Web/API/GlobalEventHandlers/onselect translation_of: Web/API/GlobalEventHandlers/onselect --- <p>{{ ApiRef() }}</p> <h3 id="Summary" name="Summary">概述</h3> <p><strong>onselect</strong>用来获取或设置当前窗口的select事件的事件处理函数</p> <h3 id="Syntax" name="Syntax">语法</h3> <pre class="eval">window.onselect = <em>funcRef</em>; </pre> <ul> <li><code>funcRef是个函数引用</code>.</li> </ul> <h3 id="Example" name="Example">例子</h3> <pre><html> <head> <title>onselect test</title> <style type="text/css"> .text1 { border: 2px solid red; } </style> <script type="text/javascript"> window.onselect = selectText; function selectText() { alert("检测到select事件!"); } </script> </head> <body> <textarea class="text1" cols="30" rows="3"> 用鼠标高亮选择一些文本,来触发select事件 </textarea> </body> </html> </pre> <h3 id="Notes" name="Notes">备注</h3> <p>只有在文本框和文本域内选择文本才会触发select事件.</p> <h3 id="Specification" name="Specification">规范</h3> <p>不属于任何公开规范.</p> <p>{{ languages( {"en": "en/DOM/window.onselect" } ) }}</p>