개발하자/자바스크립트
객체생성 이용해서 버튼만들어서 css적용하기
i구야
2015. 3. 3. 11:34
<html>
<head>
<style type="text/css">
.addStyle { background:orange; }
.removeStyle { background:skyblue; }
</style>
<script src="a.js"></script>
<script>
window.onload=function(){
initButton();
}
function initButton(){
var b1=new Button("addButton","addStyle");
var b2=new Button("removeButton","removeStyle");
}
</script>
</head>
<body>
<div id="buttonContainer">
<!--이부분을 js파일로 만들기
<input type="button" id="addButton" class="addStyle">
<input type="button" id="removeButton" class="removeStyle">
-->
</div>
</body>
</html>
a.js
==========================
function Button(a,b){
var inputTag=document.createElement("input");
inputTag.type="button";
inputTag.id=a;
inputTag.className=b;
buttonContainer.appendChild(inputTag);
}