x
 
<!DOCTYPE html>
<html>
<body>
<input type="text" id="myText" value="Some text.." onselect="myAlertFunction()">
<p>请单击按钮以选择文本字段的内容。</p>
<button type="button" onclick="mySelectFunction()">选择内容</button>
<p>HTML DOM Input Text 对象的 select() 方法选择文本字段的内容。当发生这种情况时,将触发 onselect 事件,这将触发 alert 函数。</p>
<script>
// 选择 id="myText" 的文本字段的内容
function mySelectFunction() {
  document.getElementById("myText").select();
}
// 当文本字段中的文本被选中时提示文本
function myAlertFunction() {
  alert("You selected some text!");
}
</script>
</body>
</html>