2016-05-24 3 views
1

私のウェブページでは、jqueryを使ってナビゲーションメニューをクリックしてコンテンツ(gmailなど)を変更しました。一例であるここでは、ここでjqueryイベントで表示されるコンテンツを、ユーザーが更新すると維持できますか?

<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要素内のテキストがに変更され、私はchange contentボタンをクリックした後、ある、私は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........"); 
    }); 
}); 

New contents are here.....

この時点で、ユーザーがページをリロードすると、New contents are here.....のような変更されたコンテンツのみが表示されます。 htmlで書かれたテキスト(パラグラ)ではありません。

私はできるだけ多く試しました。しかし、私は問題を解決することはできません。だから、何か提案があれば大変感謝しています。

+2

あなたは[のsessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) – anu

+0

@anuを試すことができます答えにあなたのコメントをお願いしますか? – Cloud

答えて

1
$(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); 
    }); 
}); 

Reference

check usage

関連する問題