-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (41 loc) · 1.65 KB
/
index.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
"use strict";
let addButtton=document.getElementById('add');
let resetButton=document.getElementById('reset');
let taskInput=document.getElementById('task')
let helpId=document.getElementById('helpId');
let myStorage = window.localStorage;
function addTaskFunction(){
if(validate(taskInput)){
helpId.style.display='none' // Không hiển thị hướng dẫn
localStorage.setItem(myStorage.length.toString(), taskInput.value);
myStorage=window.localStorage;
Render(myStorage);
location.reload();
} else{
helpId.innerHTML='Bạn không được nhập ký tự đặc biệt !'
}
}
function resetAllTaskFunction(){
localStorage.clear();
location.reload();
}
function Render(arr){
let ouput=document.getElementById('ouput');
ouput.innerHTML="<h3>Tasks List</h3>";
for(let i=0;i<arr.length;i++){
let key=i.toString();
ouput.innerHTML=ouput.innerHTML+ "<p>" + i.toString()+ ": "+arr[key]+"</p>";
}
}
function validate(input){
let Regex=/[0-9a-zA-Z_-ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚĂĐĨŨƠàáâãèéêìíòóôõùúăđĩũơƯĂẠẢẤẦẨẪẬẮẰẲẴẶẸẺẼỀỀỂưăạảấầẩẫậắằẳẵặẹẻẽềềểỄỆỈỊỌỎỐỒỔỖỘỚỜỞỠỢỤỦỨỪễệỉịọỏốồổỗộớờởỡợụủứừỬỮỰỲỴÝỶỸửữựỳỵỷỹ@#\s]/;
console.log(Regex.test(input.value));
if(Regex.test(input.value)){
return true;
}else {
return false;
}
}
Render(myStorage);
addButtton.addEventListener('click',addTaskFunction);
resetButton.addEventListener('click', resetAllTaskFunction);