html 자바스크립트 랜덤 색만들기
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko">
<head>
<title>Javascript 랜덤 색 만들기</title>
</head>
<body>
<div onload="OnLoad()" id="randomClass">
Javascript 랜덤 색 만들기
</div>
<button onclick="myFunction()">Click</button>
</body>
<script type="text/javascript">
function myFunction() {
var colorCode = "#" + Math.round(Math.random() * 0xffffff).toString(16);
document.getElementById("randomClass").style.color = colorCode;
}
</script>
</html>
댓글
댓글 쓰기