简体   繁体   English

重新加载页面后,保持折叠状态并展开

[英]keep state of collapse and expand after page reload

Inside an aspx page, there are five fieldset elements. 在aspx页面中,有五个fieldset元素。 Inside each fieldset next to the legend element, you can find a table element containing many rows. 在图例元素旁边的每个字段集中,您可以找到一个包含许多行的表元素。 I have added toggle functionality to each legend element so that when you click the legend element the corresponding table collapses or expands. 我已为每个图例元素添加了切换功能,因此,当您单击图例元素时,相应的表会折叠或展开。 the problem is when you reload the page all tables are expanded. 问题是当您重新加载页面时,所有表都被展开。 I want to keep the status of each table when the page is reloaded. 重新加载页面时,我想保留每个表的状态。 appreciate any kind of advice. 感谢任何形式的建议。

There are multiple solutions to this answer, such as sending a request to the server to save your state of tables, and redirect this back to the client whenever reloaded. 此答案有多种解决方案,例如向服务器发送请求以保存表状态,并在每次重新加载时将其重定向回客户端。 My knowledge of aspx pages are non-existent, so I'm coming up with a different answer. 我对aspx页面的了解不存在,所以我想出了一个不同的答案。

HTML5 WebStorage HTML5 WebStorage

You could use the HTML5 Web Storage, some info can be found here: http://www.w3schools.com/html/html5_webstorage.asp 您可以使用HTML5网络存储,可在此处找到一些信息: http : //www.w3schools.com/html/html5_webstorage.asp

An example would be to store it with javascript every time you expand or collapse a table as so: 一个例子是每次这样扩展或折叠表时都使用javascript存储它:

// Setting into the local storage
localStorage.setItem("table_"+tableElement.attr('id'), "collapsed");
// Getting from the local storage
localStorage.getItem("table_"+tableElement.attr('id'));

Please do note that the browser which this javascript is being ran on, has to support HTML5 and that when the user reloads this page on another browser, it will be set as if the user has first seen the page. 请注意,运行此javascript的浏览器必须支持HTML5,并且当用户在另一个浏览器上重新加载此页面时,将被设置为用户首次看到该页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM