Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created October 30, 2013 23:12
Show Gist options
  • Save chikoski/7241908 to your computer and use it in GitHub Desktop.
Save chikoski/7241908 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 = "";
for(var i = 0; i < nameList.length; i++){
list.innerHTML += "<li>" + nameList[i] + "</li>";
}
};
var addName = function(name){
nameList[nameList.length] = 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