Created
October 30, 2013 23:12
-
-
Save chikoski/7241908 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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