jQuery UI sortable cancel()方法
jQuery UI是一种基于网络的技术,由GUI部件、视觉效果和使用jQuery JavaScript库实现的主题组成。jQuery UI是为网页建立UI界面的最佳工具。它也可以用来建立高度互动的网络应用程序,或者可以用来轻松地添加小工具。
在这篇文章中,我们将使用jQuery UI Sortable cancel() 方法来取消当前sortable的变化,并将其恢复到当前排序开始之前的状态。对于停止和接收回调函数,我们可以使用这个工具/方法。
语法:
$( ".selector" ).sortable( "cancel" );
参数 。该方法不接受任何参数。
返回类型:该方法返回一个对象值。
CDN链接:下面是你的项目需要的jQuery UI CDN链接。
<link rel=”stylesheet” href=”https://code.jquery.com/ui/1.12.1/themes/base/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 UI Sortable cancel() 方法的用途。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet"
href=
"https://code.jquery.com/ui/1.12.1/themes/base/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>
#sortable {
list-style-type: none;
width: 50%;
}
#sortable li {
margin: 10px 0;
padding: 0.5em;
font-size: 25px;
height: 20px;
background-color: lightgreen;
}
#btn1,
#btn2 {
margin-left: 50px;
padding: 0.5;
font-size: 25px;
height: 50px;
width: 50%;
}
</style>
<script>
(function () {
("#btn1").on('click', function () {
("#sortable").sortable("cancel");
});
});
(function () {
$("#sortable").sortable();
});
</script>
</head>
<body>
<center>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<h4>jQuery UI Sortable cancel() Method</h4>
<ul id="sortable">
<li class="ui-state-default">Geeks1</li>
<li class="ui-state-default">Geeks2</li>
<li class="ui-state-default">Geeks3</li>
<li class="ui-state-default">Geeks4</li>
<li class="ui-state-default">Geeks5</li>
</ul>
<div class="res"></div>
<div>
<input type="button"
id="btn1" value="Cancel">
</div>
</center>
</body>
</html>
输出: