- jQuery Mobile 教程
- jQuery Mobile - 主頁
- jQuery Mobile - 概述
- jQuery Mobile - 設定
- jQuery Mobile - 頁面
- jQuery Mobile - 圖示
- jQuery Mobile - 過渡
- jQuery Mobile - 佈局
- jQuery Mobile - 微件
- jQuery Mobile - 事件
- jQuery Mobile - 表單
- jQuery Mobile - 主題
- jQuery Mobile - CSS 類
- jQuery Mobile - 資料屬性
- jQuery Mobile 有用資源
- jQuery Mobile - 面試問題
- jQuery Mobile - 快速指南
- jQuery Mobile - 有用資源
- jQuery Mobile - 討論
jQuery Mobile - 動態可摺疊
描述
可以動態地向摺疊集新增可摺疊內容。
示例
以下示例演示了在 jQuery Mobile 中使用“動態可摺疊元素”。
<!DOCTYPE html>
<html>
<head>
<title>Dynamic collapsible</title>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<button type = "button" data-icon = "plus" data-iconpos = "right" data-mini = "true"
data-inline = "true" id = "add_collapsible">Add collapsible</button>
<button type = "button" data-icon = "carat-d" data-iconpos = "right" data-mini = "true"
data-inline = "true" id = "expand_last">Expand last collapsible</button>
<button type = "button" data-icon = "carat-u" data-iconpos = "right" data-mini = "true"
data-inline = "true" id = "collapse_last">Collapse last</button>
<div data-role = "collapsibleset" data-content-theme = "a" data-iconpos = "right" id = "set">
<div data-role = "collapsible" id = "set1" data-collapsed = "true">
<h3>Heading 1</h3>
<p>Hi!! This is collapsible content.</p>
</div>
</div>
<script>
$( document ).on( "pagecreate", function() {
var nextId = 1;
$("#add_collapsible").click(function() {
nextId++;
var content = "<div data-role = 'collapsible' id = 'set" + nextId + "'>
<h3>Heading " + nextId + "</h3>
<p>Hi!! This is collapsible content.</p></div>";
$( "#set" ).append( content ).collapsibleset( "refresh" );
});
$( "#expand_last" ).click(function() {
$("#set").children(":last").collapsible( "expand" );
});
$( "#collapse_last" ).click(function() {
$( "#set" ).children( ":last" ).collapsible( "collapse" );
});
});
</script>
</body>
</html>
輸出
讓我們執行以下步驟,瞭解上述程式碼如何工作 -
在伺服器根資料夾中將上述 html 程式碼另存為 dynamic_collapsible.html 檔案。
使用 https:///dynamic_collapsible.html 開啟此 HTML 檔案後,將顯示以下輸出。
jquery_mobile_widgets.htm
廣告