当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


jQuery UI Sortable update用法及代码示例


jQuery UI 由使用 jQuery JavaScript 库实现的 GUI 小部件、视觉效果和主题组成。 jQuery UI 非常适合为网页构建 UI 接口。它可用于构建高度交互的 Web 应用程序,也可用于轻松添加小部件。

jQuery UI 可排序更新事件用于在用户停止排序并且 DOM 位置发生更改时触发。

用法:

使用更新回调函数初始化可排序小部件。



$(".selector").selectable({
   update:function( event, ui ) {}
});

将事件侦听器绑定到可排序的更新事件。

$( ".selector" ).on( "sortupdate", function( event, ui ) {} );

参数:

  • event:当用户停止排序并改变 DOM 的位置时触发此事件。
  • ui:这是具有 below-given 选项的对象类型。
    • helper:表示排序助手的 jQuery 对象。
    • item:表示当前拖动项的 jQuery 对象。
    • offset:辅助对象的当前绝对位置,表示为 { top, left }。
    • position:辅助对象的当前位置,表示为 { top, left }。
    • originalPosition:辅助对象的原始位置,表示为 { top, left }。
    • sender:jQuery 对象类型的可排序项从一个可排序对象移动到另一个对象。
    • placeholder:用作占位符的元素。这是 jQuery 对象类型。

CDN链接:首先,添加项目所需的jQuery UI脚本。

<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>

例:

HTML


<!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;
        }
    </style>
  
    <script>
        $(function () {
            $("#sortable").sortable({
                update:function( event, ui ) {
                    alert("Sortable Event Updated!")
                }
            });
        });
    </script>
</head>
  
<body>
    <center>
        <h1 style="color:green;">
            GeeksforGeeks
        </h1>
  
        <h4>jQuery UI Sortable update Event</h4>
  
        <ul id="sortable">
            <li class="ui-state-default">BCD</li>
            <li class="ui-state-default">CAB</li>
            <li class="ui-state-default">BAC</li>
            <li class="ui-state-default">BCA</li>
            <li class="ui-state-default">ABC</li>
        </ul>
    </center>
</body>
</html>

输出:

参考: https://api.jqueryui.com/sortable/#event-update




相关用法


注:本文由纯净天空筛选整理自GeeksforGeeks大神的英文原创作品 jQuery UI Sortable update Event。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。