Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript折叠表cookie_Javascript_Cookies_Html Table - Fatal编程技术网

javascript折叠表cookie

javascript折叠表cookie,javascript,cookies,html-table,Javascript,Cookies,Html Table,我想出了折叠桌子的脚本 <script type="text/javascript"> var rowVisible = true; function toggleDisplay(tbl) { var tblRows = tbl.rows; for (i = 0; i < tblRows.length; i++) { if (tblRows[i].className != "headerRow") { tblRows[i].style.

我想出了折叠桌子的脚本

<script type="text/javascript">
var rowVisible = true;
function toggleDisplay(tbl) {
   var tblRows = tbl.rows;
   for (i = 0; i < tblRows.length; i++) {
      if (tblRows[i].className != "headerRow") {
         tblRows[i].style.display = (rowVisible) ? "none" : "";
      }
   }
   rowVisible = !rowVisible;
}
</script>   


<div class="datagrid"><table id="thread_1">
<thead><tr class="headerRow">     

      <th WIDTH="100"><a href="#" onclick="toggleDisplay(document.getElementById('thread_1'))" STYLE="color: white">SLO</a></th>

var rowVisible=true;
功能切换显示(tbl){
var tblRows=tbl.rows;
对于(i=0;i

它工作的很好,但我的问题是,我想保存状态时,人们离开网站。我想最简单的方法就是用饼干。我只是从来没有做过这样的事。我该怎么做呢?

如果您不需要支持,比如说IE7,您可以使用浏览器本地存储

//确定行是否隐藏的标志
var rowsVisible=localStorage.getItem('rowsVisible'),
//表格处理程序
table=document.getElementById('table');
//localStorage中尚不存在“rowHidden”
if(rowsVisible==null){
rowsVisible=true;
}否则{
//本地存储返回字符串
rowsVisible=rowsVisible=='true'?true:false;
}
切换显示(表,行可见?“”:“无”);
document.getElementById('toggleBtn')。addEventListener('click',function(){
切换显示(表格);
},假);
功能切换显示(tbl){
var tblRows=table.rows,
模式=行可见?“”:“无”;
对于(i=0;i

演示:

Google HTML5本地存储。Cookie用于获取服务器上需要的信息。在我的chrome或Firefox中不起作用。可能不会在mobile eater上工作,witch有点大不了。而且所有新的移动浏览器都支持本地存储(iOS、Android、Blackberry、IE mobile),但只能在一个表上工作。我如何使它与2个或更多的工作?我将此代码包装到
tableExpander
函数(演示:)。只需拨打
tableExpander('my-table-id')
您知道我其他类似问题的答案吗?