Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.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 如果用户刷新页面,是否可以维护jquery事件显示的内容?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 如果用户刷新页面,是否可以维护jquery事件显示的内容?

Javascript 如果用户刷新页面,是否可以维护jquery事件显示的内容?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,在我的网页中,我通过使用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

在我的网页中,我通过使用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>
我想要的要点是,在单击
更改内容
按钮后,
p
元素中的文本现在更改为
新内容在这里….

此时,如果用户重新加载页面,我只想显示已更改的内容,如
此处有新内容….
。不是用
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);
    });
});


你可以试试@anu,你能发表评论回答吗?
$(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);
    });
});