如何改變 HTML 元素的可見度,背景色

改變背景顏色:

<!DOCTYPE html>
<html>
<head>

<script>
function bgChange(bg) {
  document.body.style.background = bg;
}
</script>
</head>
<body>

<h1>改變背景顏色</h1>

<p>請把鼠標移動到方塊上。</p>

<table style="width:300px;height:100px">
  <tr>
    <td onmouseover="bgChange(this.style.backgroundColor)" 
    onmouseout="bgChange('transparent')"
    style="background-color:Khaki">
    </td>
    <td onmouseover="bgChange(this.style.backgroundColor)" 
    onmouseout="bgChange('transparent')"
    style="background-color:PaleGreen">
    </td>
    <td onmouseover="bgChange(this.style.backgroundColor)" 
    onmouseout="bgChange('transparent')"
    style="background-color:Silver">
    </td>
  </tr>
</table>

</body>
</html>

改變可見度:

<!DOCTYPE html>
<html>
<body>

<p id="p1">
這是一段文本。
這是一段文本。
這是一段文本。
</p>

<input type="button" value="隱藏文本" 
onclick="document.getElementById('p1').style.visibility='hidden'">

<input type="button" value="顯示文本"
onclick="document.getElementById('p1').style.visibility='visible'">

</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章