页面刷新没有更改

时间:2016-09-05 10:44:42

标签: javascript

我创建了一个添加按钮。当我点击按钮时,它会创建一张新卡。当我点击卡片时,它会显示一个输入字段,我可以在其中输入例如我的名字。

我想要做的是:我不想在浏览器刷新时丢失更改。所以,例如,如果我在屏幕上有两张卡片,而我正在编辑一张卡片,那么当我刷新页面时,两张卡片和编辑模式下的卡片仍然完全相同。

我已经尝试了一些东西,但遗憾的是它没有用。 你能帮帮我吗?

HTML

<button class="plus">
  <div class="item">
    <p>+</p>

  </div>
</button>

<div id="newCardHolder">

</div>

<div id="cardPrototype" class="card" style="display:none;">
    <p  class="delete">x</p>
  <span>Title</span>
  <form name="theform" style="display:none;">
    <input class="input-feld" type="text">
    <br>
    <input class="input-feld " type="text">
    <br>
    <input class="speichern"type="button" onClick="new Person()" value="Speichern">
    <input class="abbrechen"type="button" onClick="new abbrechen()" value="Abbrechen">
  </form>
</div>

CSS

/*Input-feld*/
.input-feld {
    font-family: TheSans Swisscom;
    margin: 5px 3px;
    padding: 3px;
    width:250px;
}

.card {
            width:300px;
            margin-right:5px; 
            margin-left:5px; 
            margin-bottom:10px; 
            float: left;
            padding:10px; 
            background-color: #BBBBBB; 
            border: 1px solid #ccc; 
            border-radius:10px;
            position:relative;
}

.delete {
            font-family:'TheSans Swisscom';
            right:12px;
            top:0;
            position:absolute;
}

.speichern{
    font-family:'TheSans Swisscom';
    background-color: greenyellow; 
    border-radius: 5px;
    margin-top: 5px;
    border-color:greenyellow;
}

.abbrechen{
    font-family: "TheSans Swisscom";
    background-color: red;
    border-radius: 5px;
    margin-left: 10px;
    border-color: red;
}    /*kärtchen*/

的JavaScript

$(document).ready(function () {
    $('button.plus').on('click', function () {
        var newCard = $('#cardPrototype').clone(true); 
        $(newCard).css('display', 'block').removeAttr('id');
        $('#newCardHolder').append(newCard);
    });

    $("body").on("click", ".card", function () { 
        $(this).find('.input-feld').attr('placeholder', $(this).find('span').text());
        $(this).find('span').hide();
        $(this).find('form').show();
    });


    $('.card').on("click", function () {
        $('.card').find('form').hide();
        $('.card').find('span').show();
    });

/*delete button*/
$("body").on('click', '.card .delete', function() {
    $(this).closest('.card').remove();
});
});

/*Page reloader*/
window.onbeforeunload = function () {
    localStorage.setItem(name, $('#card').val());
    localStorage.setItem(name,$('#input-feld').val());
}
window.location.reload()

0 个答案:

没有答案