From HTML
优质
小牛编辑
126浏览
2023-12-01
描述 (Description)
您可以使用类和数据属性启用和禁用sortable,如下所示 -
S.No | 类型和描述 |
---|---|
1 | open-sortable 需要为任何HTML元素启用可排序模式。 |
2 | close-sortable 需要禁用可排序模式。 |
3 | toggle-sortable 需要切换可排序模式。 |
4 | data-sortable=".sortable" 每当您的应用在应用中有多个可排序列表时,您需要使用此属性指定适当的可排序列表作为HTML元素的附加属性。 |
例子 (Example)
以下示例指定在Framework7中的链接上启用,禁用和切换HTML元素的排序 -
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, initial-scale = 1,
maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" />
<meta name = "apple-mobile-web-app-capable" content = "yes" />
<meta name = "apple-mobile-web-app-status-bar-style" content = "black" />
<title>Sortable from HTML</title>
<link rel = "stylesheet"
href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" />
<link rel = "stylesheet"
href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" />
</head>
<body>
<div class = "views">
<div class = "view view-main">
<div class = "navbar">
<div class = "navbar-inner">
<div class = "center sliding">Sortable from HTML</div>
</div>
</div>
<div class = "pages navbar-through">
<div data-page = "index" class = "page navbar-fixed">
<div class = "page-content">
<div class = "content-block">
<p><a href = "#" data-sortable = ".sortable" class = "open-sortable">Click here to enable sortable</a></p>
<p><a href = "#" data-sortable = ".sortable" class = "close-sortable">Click here to disable sortable</a></p>
<p><a href = "#" data-sortable = ".sortable" class = "toggle-sortable">Click here to toggle sortable</a></p>
</div>
<div class = "list-block sortable">
<ul>
<li>
<div class = "item-content">
<div class = "item-media"><i class = "icon icon-form-name"></i></div>
<div class = "item-inner">
<div class = "item-title">Sachin</div>
<div class = "item-after">India</div>
</div>
</div>
<div class = "sortable-handler"></div>
</li>
<li>
<div class = "item-content">
<div class = "item-media"><i class = "icon icon-form-name"></i></div>
<div class = "item-inner">
<div class = "item-title">Smith</div>
<div class = "item-after">Australia</div>
</div>
</div>
<div class = "sortable-handler"></div>
</li>
<li>
<div class = "item-content">
<div class = "item-media"><i class = "icon icon-form-name"></i></div>
<div class = "item-inner">
<div class = "item-title">Morgan</div>
<div class = "item-after">England</div>
</div>
</div>
<div class = "sortable-handler"></div>
</li>
<li>
<div class = "item-content">
<div class = "item-media"><i class = "icon icon-form-name"></i></div>
<div class = "item-inner">
<div class = "item-title">Dhoni</div>
<div class = "item-after">India</div>
</div>
</div>
<div class = "sortable-handler"></div>
</li>
<li>
<div class = "item-content">
<div class = "item-media"><i class = "icon icon-form-name"></i></div>
<div class = "item-inner">
<div class = "item-title">Gayle</div>
<div class = "item-after">West Indies</div>
</div>
</div>
<div class = "sortable-handler"></div>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script type = "text/javascript"
src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script>
<script>
// here initialize the app
var myApp = new Framework7();
// If your using custom DOM library, then save it to $$ variable
var $$ = Dom7;
// Add the view
var mainView = myApp.addView('.view-main', {
// enable the dynamic navbar for this view
dynamicNavbar: true
});
</script>
</body>
</html>
输出 (Output)
让我们执行以下步骤,看看上面给出的代码是如何工作的 -
将上面给出的HTML代码保存为服务器根文件夹中的enable_disable_sortable_from_html.html文件。
以http://localhost/enable_disable_sortable_from_html.html打开此HTML文件,输出显示如下。
该示例指定启用,禁用和切换链接上HTML元素的排序。