-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.js
65 lines (51 loc) · 1.33 KB
/
js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
let addbutton=document.getElementById('addbtn');
let txtinpt=document.getElementById('txtinput');
let tskfield=document.getElementById('tasksfield');
let addaud=document.getElementById('addaudio');
let rmaud=document.getElementById('removeaudio');
let todo;
var newtask;
if(localStorage.getItem("todoapp")===null)
todo=[];
else
todo=JSON.parse(localStorage.getItem("todoapp"));
//
//
addbutton.addEventListener('click',function(){
if(txtinpt.value!=""){
newtask=document.createElement('li');
newtask.innerHTML=txtinpt.value;
todo.push(txtinpt.value);
localStorage.setItem("todoapp",JSON.stringify(todo));
txtinpt.value='';
addaud.play();
tskfield.appendChild(newtask);
newtask.addEventListener('dblclick', function(){
tskfield.removeChild(newtask);
rmaud.play();
});
}
else
alert('must enter a character');
});
var a=document.querySelector('ul');
a.addEventListener('dblclick',clickevent);
function clickevent(e){
var vb=e.target.innerHTML;
todo.splice(todo.indexOf(vb),1);
tskfield.removeChild(e.target);
rmaud.play();
//here
localStorage.setItem("todoapp",JSON.stringify(todo));
};
window.onload=function(){
if(localStorage.getItem("todoapp")!=null){
todo=JSON.parse(localStorage.getItem("todoapp"));
var i;
for(i=0;i<todo.length;i++)
{newtask=document.createElement('li');
newtask.innerHTML=todo[i];
tskfield.appendChild(newtask);
}
}
};