Created
March 16, 2015 11:42
-
-
Save crongro/63dd415b90f18f721f0b to your computer and use it in GitHub Desktop.
0315_2
This file contains 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>testcode</title> | |
<style type="text/css" media="screen"> | |
.testButton{width:400px;height:50px;} | |
.showLayer{width:400px;height:400px;background:pink} | |
.showLayer > div {padding: 10px; box-sizing: border-box; } | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<button class="testButton"> | |
</button> | |
</div> | |
<div class="showLayer" style="display:none;"> | |
</div> | |
<script> | |
var sDATA = [ | |
{ | |
"name" : "NHN NEXT", | |
"age" : 4, | |
"location" : "seongNam city pangyo dong" | |
}, | |
{ | |
"name" : "KAIST", | |
"age" : 29, | |
"location" : "daejeon" | |
}, | |
{ | |
"name" : "SDS MULTICAMPUS", | |
"age" : 10, | |
"location" : "seoul kangNam gu" | |
} | |
]; | |
var myObj = { | |
registerEvents : function() { | |
var elBase = document.querySelector(".testButton"); | |
elBase.addEventListener("click", function(e){ | |
this.toggleLayer(); | |
}); | |
}, | |
toggleLayer : function(){ | |
var elTarget = document.querySelector(".showLayer"); | |
var sCurDisplayStyle = elTarget.style.display; | |
if(sCurDisplayStyle ==="none") { | |
elTarget.style.display = "block"; | |
insertMessage(elTarget); | |
} else { | |
elTarget.style.display = "none"; | |
} | |
}, | |
insertMessage : function(elParent) { | |
var sResult = ""; | |
for (var i = 0 , len = sDATA.length; i < len; i++) { | |
sResult += "<div><h3>" + sDATA[i].name + "</h3>" + | |
"<span>" + sDATA[i].location + "</span></div>"; | |
} | |
elParent.innerHTML = sResult; | |
} | |
}; | |
window.addEventListener("load", function(){ | |
myObj.registerEvents(); | |
},false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment