Jquery教程
Jquery动效
Jquery HTML/CSS
Jquery 事件
jquery常用

Jquery select()

当在文本区域或文本字段中标记或选择文本时,发生jQuery select事件。此事件仅限于<input type="text">字段和<textarea>框。当发生select事件时,select()方法将附加一个要运行的函数。
语法:
$(selector).select()
它触发选定元素的选择事件。
$(selector).select(function)
它为select事件添加了一个函数。

jQuery select()事件的参数

参数 说明
function 这是一个可选参数。用于指定执行select事件时要运行的函数。

jQuery select()事件的示例

让我们以一个示例来演示jQuery select()事件。
 <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>select demo</title>
  <style>
  p {
    color: red;
  }
  div {
    color: blue;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 <p>选择框上的文本: 单击并拖动鼠标以选择文本。</p>
  <input type="text" value="lidihuo.com">
  <input type="text" value="sssit.org">
  <div></div>
 <script>
$(":input").select(function() {
  $("div").text("已选择某些文本").show().fadeOut(2000);
});
</script>
 </body>
</html>
输出:
选择框上的文本: 单击并拖动鼠标以选择文本。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4