jQuery并保存页面之间的参数

标签 jquery html css spring

是否可以记住 div 的高度?例如,在单个网站上,我展开包含一些内容的 div,然后单击内容不同但具有相同 div(相同 ID 和类)的另一个页面。不幸的是,所有内容都会刷新并失去 div 的高度。

我得到了 html 中的框架效果(但你怎么看它并不像我想的那样工作)。怎么样?将数据保存在 session 中?需要示例...

如果有人问,我正在使用 jQuery,Spring MVC

最佳答案

您可以简单地使用 HTML5 localStorage 机制。

您可以根据需要使用.height().innerHeight()outerHeight()

enter image description here

Here's the example - jsfiddle.net/xK0nB1n

jquery

if(localStorage.divheight) //extract the old height
{ 
    // handle the height as you want here
    alert('Old height from local storage: '+ localStorage.divheight);
}

//Code just to show the mechanism of LocalStorage
$(document).ready(function(){    
   $('#result').click (function () {

        //Remember the height
      localStorage.divheight = $("div").height(); 

       //Tell the user the freshly stored height
      alert("New height: "+localStorage.divheight);
    });
});

HTML

<div id="result">
    Some number of lines here....
    Lorem ipsum dolor sit amet, consectetur adipisicing elit
    . Fuga earum id fugit veritatis! Pariatur, magni.
</div>

关于jQuery并保存页面之间的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25580753/

相关文章:

html - css - div 可以溢出它的相对溢出 :hidden container?

javascript - 我如何找到从 jquery 中的表单提交事件中单击的按钮?

javascript - 清除前一个值后保护文本框不取该空白值

javascript - 如何使用带有变量的javascript访问对象数组

javascript - 在元素 SVG 中使用 JavaScript 或 jQuery 事件点击?

html - 用CSS居中固定宽度的元素

php - 仅获取新条目数据库 mysql

javascript - 不同页面加载不同的js文件还是一起加载?

javascript - 根据背景颜色改变汉堡菜单的颜色

Css类不改变文本框的边框颜色