jQuery UI的Selectable unselecting事件
jQuery UI由使用jQuery JavaScript库实现的GUI部件、视觉效果和主题组成。jQuery UI非常适合为网页建立UI界面。它可以用来建立高度互动的网络应用程序,也可以用来轻松地添加小工具。
jQuery UI的Selectable unselecting事件是用来在选择操作过程中,对每个从选择中移除的元素进行触发。
语法:
- 用unselecting的回调函数初始化可选择部件。
$( ".selector" ).selectable({
unselecting: function( event, ui ) {}
});
- 将一个事件监听器绑定到可选择的unselecting事件上。
$( ".selector" ).on(
"selectableunselecting",
function( event, ui ) {}
);
参数:该方法接受以下参数
- event。该事件在选择项目时被触发。
- ui。这个参数是一个jQuery对象,用于当前正在选择的可选择项目。
- unselecting。这个参数是元素类型的,它是当前被选中的项目。
CDN链接。添加以下jQuery Mobile脚本,这将是你的项目所需要的。
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css”>
<script src=”https://code.jquery.com/jquery-1.12.4.js”></script>
<script src=”https://code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
例子:这个例子描述了jQuery Mobile Selectable unselecting事件的用途。
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href=
"https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src=
"https://code.jquery.com/jquery-1.12.4.js">
</script>
<script src=
"https://code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<style>
h1 {
color: green;
}
#list .ui-selecting {
background:greenyellow;
}
#list .ui-selected {
color: white;
background: green;
}
</style>
</head>
<body>
<center>
<h1>GeeksforGeeks</h1>
<h3>jQuery UI Selectable unselecting Event</h3>
<h3>GeeksforGeeks Subjects</h3>
<ul id="list" style="list-style: none">
<li>Data Structure</li>
<li>Algorithm</li>
<li>C++</li>
<li>Java</li>
<li>HTML</li>
<li>Bootstrap</li>
<li>PHP</li>
</ul>
<div class="res"></div>
<script>
(document).ready(function () {
("#list").selectable();
("#list").selectable({
unselecting: function(event, ui) {
(".res").html("Unselecting Event Triggered");
},
});
});
</script>
</center>
</body>
</html>
输出: