jquery移动列表视图和可折叠集在返回时打开
jquery mobile listview and collapsible set open on going back
我有一个三层列表,它在末尾转到另一个页面。。。所以当我从另一个页面回来时,我希望列表项打开,并指示哪个项目被点击了。
怎么做
<div data-role="collapsible" >
<h2>Header</h2>
<ul data-role="listview">
<li><a href="#item1">item-1</a></li>
<li><a href="#">item-2</a></li>
<li><a href="#">item-3<span class="ui-li-count">12 set</span></a></li>
</ul>
</div>
-----------------------------------------------------------------
<div data-role="page" id="item1">
<div data-role="header">
<a href="#mainPage" data-role="button" data-icon="arrow-l">Back</a>
<h1>item1</h1>
</div>
<div data-role="content">
<div class="container">
<ul data-role="listview">
**<li><a href="material/set1.html" rel="external">Set 1</a></li>**
<li><a href="#">Set 2</a></li>
<li><a href="#">Set 3</a></li>
</ul>
</div>
</div>
<div data-role="footer">
<h4>Footer</h4>
</div>
</div>
-----------------------------------------------------------------
现在,从主列表中,当用户点击项目1时,它会显示另一个集合-1、集合-2、集合-3等列表。现在,点击集合-1时,用户会被带到另一个"外部页面"。
当用户从外部页面单击后退按钮时,它会显示,表示已单击集合1,可折叠集合应打开。。目前,我得到的可折叠集已折叠,没有迹象表明用户是
它非常容易上手。一种方法是使用cookie来存储您在导航到其他页面时单击的列表项。
如果你决定使用这种方法,你将需要插入jquery cookie——https://github.com/carhartl/jquery-cookie
我没有太多时间做演示,这很快,但你可以很容易地从演示中看到发生了什么。我所做的只是给列表项一个id和(a)类id,这样我们就知道点击了哪一个,把背景色调成哪一个来表示它被点击了。
如果你有多个扩展的列表,那么将可扩展列表视图的id存储到另一个cookie中,并像我在演示中那样扩展正确的列表。
演示
http://jsfiddle.net/wgt88h3n/
$("#listview").on("click", ">li", function(event, ui) { // this function gets the id from the list items
var id = $(this).closest("li").attr('id');
$.cookie('item', id); // store the id of the list item to a cookie
});
$("#topage2").on("click", function(event, ui) {
var item = $.cookie('item'); // lets get the item of the cookie
$(".item1, .item2, .item3").css({backgroundColor: '#f6f6f6;'}) // lets set the background color back to normal
$.mobile.changePage( "#page2" , { transition: "pop" }) ///change to page 2
});
$("#topage1").on("click", function(event, ui) {
$.mobile.changePage( "#page1" , { transition: "pop" })
$( "#mylist" ).collapsible( "expand" ); // expand the collapsible list. if you have more lists,,, to expand the correct one, use another cookie and use the same method when we stored the list item.
var item = $.cookie('item'); /// read the cookie item
$("." + item ).css({backgroundColor: 'rgba(72, 121, 49, 0.38)'}) ///set the background color of the last item clicked to green
});
相关文章:
- 可折叠树在第二级不显示子树
- 引导程序/轨道-可折叠导航栏没有'我不能在手机上工作
- 只使用CSS创建可折叠菜单或spry菜单
- 可以't以编程方式关闭jQuery移动弹出窗口中的可折叠部分
- QML中的可折叠面板
- 可折叠容器/柱.添加多个链接
- 如何将垂直选项卡式内容面板更改为具有媒体查询和 jquery 的响应式可折叠面板
- 如何防止我的引导可折叠框滚动页面
- 返回可用作函数的 Javascript 对象
- 如何以可扩展和可折叠的树形结构显示XML模式
- 单击一个后自动折叠所有其他可折叠内容
- 可折叠侧边栏/导航菜单
- 可折叠<UL><李>不起作用
- Ext JS 5.1:当可折叠为true时,无法对面板进行标题设置
- jQuery与可折叠列表冲突
- Postback后保持可折叠潜水打开
- 如何在HTM文件中创建与可折叠面板扩展程序等效的扩展程序
- 为d3.js可折叠树设置背景
- 如何从对象返回可读字符串
- jquery移动列表视图和可折叠集在返回时打开