これはとても簡単で、検索しましたが正確な答えが見つかりませんでした。
私がやりたいのは、リンクをクリックすると色が変わる div を持つことだけです。3色か4色くらいは欲しいです。どうすればいいのですか?
ありがとう!
これはとても簡単で、検索しましたが正確な答えが見つかりませんでした。
私がやりたいのは、リンクをクリックすると色が変わる div を持つことだけです。3色か4色くらいは欲しいです。どうすればいいのですか?
ありがとう!
ここに簡単な解決策があります
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function changeColor(color){
var div = document.getElementById('box');
div.style.backgroundColor = color;
}
</script>
</head>
<body onload="changeColor('green')">
<div id="box" style="width:200px; height:200px;"></div>
<a href="#" onclick="changeColor('yellow')">Yellow</a>|
<a href="#" onclick="changeColor('green')">Green</a>|
<a href="#" onclick="changeColor('blue')">Blue</a>|
<a href="#" onclick="changeColor('white')">White</a>
</body>
</html>