8 html javascript php jquery local-storage
我有一个html页面1.html
,我想获得一些文本内容并js.js
使用jquery 将其存储到文件中以获取id的文本.
此代码只能在1.html
页,在这里我想从复制文本,但不是在2.html
文件中.
这是我的代码.请注意,如果我将文本存储在localstorage setter第二个参数中,它就可以工作.
$( document ).ready(function() {
var c1Title= $('#r1c1Title').text();
//changing c1Title to any String content like "test" will work
localStorage.setItem("t1",c1Title);
var result = localStorage.getItem("t1");
$("#title1").html(result);
alert(result);
});
Run Code Online (Sandbox Code Playgroud)
这是我在Github上工作的完整演示:
您需要使用localStorage或cookie.
在第一页上,使用以下代码:
localStorage.setItem("variableName", "variableContent")
Run Code Online (Sandbox Code Playgroud)
这variableName
为域设置了localStorage变量和内容variableContent
.您可以将这些名称和值更改为您想要的任何名称和值,它们仅用作示例
在第二页上,使用以下代码获取值:
localStorage.getItem("variableName")
Run Code Online (Sandbox Code Playgroud)
这将返回存储的值variableName
,即variableContent
.
localStorage.removeItem("variableName")
.localStorage
到sessionStorage
在你的代码的所有实例) 归档时间: |
|
查看次数: |
9473 次 |
最近记录: |