在我的网页中,我通过使用 jquery 单击导航菜单来更改内容(如 gmail)。这是例子,
<p>
I have a classifieds website, and on the page where ads are showed,
I am creating a "Send a tip to a friend" form... So anybody who wants can send a tip of the ad to some friends email-adress.
I am guessing the form must be submitted to a php page right? When submitting the form, the page gets reloaded... I don't want that... Is there any way to make it not reload and still send the mail? Preferrably without ajax or jquery... Thanks
</p>
<button id="chg">
Change content
</button>
这是我用 jquery 尝试的,
$(document).ready(function(){
var isnew = "";
console.log(isnew);
if(isnew == true) {
console.log("check "+isnew);
$("p").html("New contents are here........");
}
$("#chg").click(function(){
isnew = true;
console.log(isnew);
$("p").html("New contents are here........");
});
});
我想要的要点是,在我点击 change content
按钮后,现在 p
元素中的文本更改为 New contents are here.. ...
。
此时,如果用户重新加载页面,我只想显示更改的内容,如 New contents are here.....
。不是用 html
编写的文本(段落)。
我已经尽力了。但我无法解决问题。因此,我非常感谢任何建议。
最佳答案
$(document).ready(function(){
if (sessionStorage.getItem("newContent")) {
// Restore the contents
$("p").html(sessionStorage.getItem("newContent"));
}
$("#chg").click(function(){
var newCont = "New contents are here........";
$("p").html(newCont);
sessionStorage.setItem("newContent", newCont);
});
});
关于javascript - 如果用户刷新页面,是否可以维护 jquery 事件显示的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37411164/