Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created October 30, 2013 23:13
Show Gist options
  • Save chikoski/7241918 to your computer and use it in GitHub Desktop.
Save chikoski/7241918 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<div>
<input type="text" id="name">
<button id="btn">追加</button>
</div>
<ul id="list"></ul>
</body>
</html>
var nameList = [];
var btn = document.getElementById("btn");
var list = document.getElementById("list");
var input = document.getElementById("name");
var showNameList = function(){
list.innerHTML = "<li>" + nameList.join("</li><li>") + "</li>";
};
var addName = function(name){
nameList.push(name);
};
btn.onclick = function(){
addName(input.value);
showNameList();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment