我需要帮助更改标题中的文本内容。用户在第一页上输入名称,并且应该将下一页上的 h2 更改为键入的内容。任何帮助将不胜感激,是的,我添加了 Cookie.js 库。 这是我到目前为止所拥有的:
进入页面:
<form action="Lab12-p2.html" method="post">
<h3>Enter Name </h3>
<label for="name">Username: </label>
<input id="name" type="text" name="name" />
<input id="submit2" type="submit" value="Submit" />
</form>
第 2 页:
<h2 id ="username"> Hi there! </h2>
Javascript:
$("#name").blur(function(event) {
var test = event.target.value;
Cookie.set("content", test);
var ger = Cookie.get("content");
$("#username").html("Hi" + content);
});
最佳答案
如果您使用的是 html5,也可以这样做
$("#name").blur(function(event) {
var test = event.target.value;
localStorage.setItem("content", test);
$("#username").text("Hi " + localStorage.getItem("content"));
});
关于javascript - 使用 cookie 更改 header 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47524263/