0
我試圖在點擊相應顏色的按鈕時更改標題的部分和邊框底部顏色的背景顏色。例如,當點擊藍色按鈕時,我希望該部分的背景顏色改變爲這種顏色:rgb(203,223,242)和標題的下邊框以改變爲rgb(225,255,255)。使用javascript更改標題的部分和邊框底部顏色的背景顏色
我已經嘗試過使用document.getElementsByTagName('section')並檢索節標記,但在此之後,當我嘗試用下面的一段代碼更改背景色時secColor.style.backgroundColor ='rgb(203 ,223,242)'沒有任何反應。
預先感謝您!
下面是HTML代碼的一部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>List</title>
<link rel="stylesheet" href="StyleSheet.css"/>
</head>
<body>
<section>
<header>
<form>
<button>₪</button>
<div>
<p>Colors</p>
<button id="blue" onclick="functionBlueSection('rgb(203, 223, 242)'); functionBlueHeader('(225, 255, 255)');"></button>
<button id="red" onclick="functionRedSection(); functionRedHeader();"></button>
<button id="yellow" onclick="functionYellowSection(), functionYellowHeader()"></button>
</div>
</form>
</header>
<ul>
<li>
<a href="#">List item</a>
<ul>
<li>
<a href="#">Sublist item</a>
</li>
<li>
<a href="#">Sublist item</a>
</li>
<li>
<a href="#">Sublist item</a>
</li>
<li>
<a href="#">Sublist item</a>
</li>
</ul>
</li>
</ul>
</section>
<!--Javascript-->
<script type="text/javascript">
function functionBlueSection() {
var secColor = document.getElementsByTagName('section');
secColor.style.backgroundColor = 'rgb(203, 223, 242)';
}
var headColor = document.getElementsByTagName('header');
function functionBlueHeader(){
headColor.style.borderBottom = 'thin solid rgb(225, 255, 255)';
}
</script>
</body>
</html>