私は現在、単純なバニラのJavaScript To-doアプリケーションを書いています。すべてはうまく見えますが、新しいlocalStorageにデータを保存すると、私はできません。 localStorageを使用したことはありません。私は多くの記事を読んだことがあります。シンプルなものを試してみますが、アプリケーションを正しく動作させることはできません。入力したデータをリフレッシュすると保存されますが、消えません。現在は...アプリケーションへのリンクです。localstorageのTo-doアプリ
****私はバニラJAVASCRIPT、JQUERYユーザーは、いくつかのドス、およびリフレッシュを行う場合は****
だから基本的に、私はすべてが画像ブローのように、滞在したいです。
HTML:
<body>
<div class="holder">
<div>
<input type="text" />
</div>
<button id="add">Add</button>
<div class="results"></div>
</div>
</body>
JS:
document.addEventListener('DOMContentLoaded',function(){
let holder = document.querySelector('.holder'),
addBtn = document.querySelector('#add'),
removeBtn = document.querySelector('#remove'),
resultBox = document.querySelector('.results');
let input = document.getElementsByTagName('input')[0];
function setAttributes(element,attrs){
for(let i in attrs){
element.setAttribute(i,attrs[i]);
}
}
setAttributes(input,{
'placeholder' : 'Enter To-Do',
'name' : 'todo'
});
function addtoBtn(){
addBtn.addEventListener('click',function(event){
if(input.value !== ''){
let openingDiv = '<div class="todo"><span>';
let closingDiv = '</span><button class="edit">Edit</button><button class="save">Save</button><button class="removeBtn">Remove</button></div>';
resultBox.innerHTML += openingDiv + input.value + closingDiv;
input.value = '';
event.preventDefault();
} else{
alert('Enter To-do!');
}
let innerBtn = document.querySelectorAll('.removeBtn');
let editBtn = document.querySelectorAll('.edit');
let saveBtn = document.querySelectorAll('.save');
for(let collection = 0 ; collection < saveBtn.length ; collection++){
saveBtn[collection].style.display = "none";
}
function removeToDo(){
this.parentNode.style.display = 'none';
}
for(let k = 0 ; k < innerBtn.length ; k++){
innerBtn[k].addEventListener('click',removeToDo);
}
function startContentEdit(){
this.previousSibling.contentEditable = true;
this.previousSibling.style.padding = "10px";
this.previousSibling.style.boxShadow = "0 0 15px #fff";
this.previousSibling.style.borderRadius = "10px";
this.previousSibling.style.transition = "all .4s";
this.style.display = "none";
for(let el = 0 ; el < saveBtn.length ; el++){
this.nextSibling.style.display = 'inline-block';
}
}
for(let j = 0 ; j < editBtn.length ; j++){
editBtn[j].addEventListener('click',startContentEdit);
}
function saveContentEdit(){
this.style.display = 'none';
for(let j = 0 ; j < editBtn.length ; j++){
this.previousSibling.style.display = "inline-block";
this.parentNode.firstElementChild.style.display = "block";
this.parentNode.firstElementChild.contentEditable = false;
this.parentNode.firstElementChild.style.padding = "0px";
this.parentNode.firstElementChild.style.boxShadow = "0 0 0";
}
}
for(let x = 0 ; x < saveBtn.length ; x++){
saveBtn[x].addEventListener('click',saveContentEdit);
}
});
}
addtoBtn();
});
私が言ったように、私は多くの記事を見ましたが、私は私の解決策への答えを見つけることができません。 申し訳ありませんが、それは私の最初のjavascriptアプリケーションです。Dと私はとても興奮していますので、完全に動作させたいのです。
再開:
それは新しい生成
<div class="todo></div>
コンテナを保存するために、のlocalStorageかのsessionStorageで可能ですか?
は悪いアイデアのように聞こえるのです。これはコードの*ロット*、おそらくスタックオーバーフローの質問にはあまりにも多すぎます。あなたは何を抱えているのかをより詳細に明らかにし、問題に関連するコードを表示できますか? –