<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);
}
'개발하자 > 자바스크립트' 카테고리의 다른 글
객체생성해서 appendChild하기 (0) | 2015.03.03 |
---|---|
객체생성이용,외부js파일이용,클릭이벤트 등록하기 (0) | 2015.03.03 |
외부파일로 css스타일 적용 시키고 js이벤트 주기 (0) | 2015.03.03 |
iframe이용,페이지 열기 (0) | 2015.03.03 |
이전페이지 다음페이지로 이동하기 (0) | 2015.03.03 |