프런트엔드 - JS의 임의 배경색 변경

12263 단어 프런트엔드 #HTML
모처럼 수강(작은 소리bb)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
	<script type="text/javascript">
		var table,color;
		function $(id){return document.getElementById(id);}
		function randomInt(){
			var rancor=Math.floor(Math.random()*256);
			return rancor;
		}
		function ChangeColor(){
			table=$("FirstTab");
			color=table.getAttribute("bgcolor");// 
			var r=randomInt().toString(16);/// 16 
			var g=randomInt().toString(16);
			var b=randomInt().toString(16);
			var rescolor="#"+r+g+b;
			table.setAttribute("bgcolor",rescolor);/// 
		}
		function ResetColor(){
			///color="#179BD6";
			table.setAttribute("bgcolor",color);
		}
	</script>
</head>

<body>
	<form method="post" >
		<table align="center" border="1" bgcolor="#179BD6" width="500px" id="FirstTab">
			<tr>
				<caption> </caption>
				<td> </td>
				<td> </td>
				<td> </td>
				<td> </td>
			</tr>
			<tr>
				<td>1</td>
				<td>Cutele</td>
				<td>261</td>
				<td> </td>
			</tr>
			<tr>
				<td>2</td>
				<td> </td>
				<td>20192203262</td>
				<td> </td>
			</tr>
			<tr>
				<td colspan="4">
					<input type="button" value="change color" onClick="ChangeColor()">
					<input type="button" value="reset color" onClick="ResetColor()">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

좋은 웹페이지 즐겨찾기