Ajax Loader
×
HTML
<ol id="files">
1
<ol id="files">
2
  <li>NO FILES
3
    <blockquote>WHY??????</blockquote>
4
  </li>
5
</ol>
6
<input type="text" placeholder="File name" id="fname"><BR><textarea placeholder="File content" id="fcont"></textarea>
7
<br>
8
<button id="go">Push data to filelist</button>
 
CSS
blockquote {
1
blockquote {
2
  padding:5px 10px;
3
  margin:0;
4
  border-left:solid 3px gainsboro;
5
  background:#eee
6
}
 
JavaScript
var list = document.getElementById("files"),
1
var list = document.getElementById("files"),
2
    files = JSON.parse(localStorage.files);
3
function init() {
4
  if(files) {
5
    list.innerHTML = ""
6
  }
7
  for (i=0;i<files.length;i++) {
8
    var li = document.createElement("li");
9
    li.textContent = files[i].name;
10
    var bq = document.createElement("blockquote");
11
    bq.textContent = files[i].content;
12
    list.appendChild(li);
13
    li.appendChild(bq)
14
  }
15
}
16
function pushData() {
17
  localStorage.files = JSON.parse(files.push({
18
    name: document.getElementById("fname").value,
19
    content: document.getElementById("fcont").value
20
    init();
21
  });
22
}
23
init()
 

Untitled

CSSDeck G+