如何用 JavaScript 設定元素的不透明度級別?
使用 JavaScript 中的 opacity 屬性設定不透明度級別。你可以嘗試執行以下程式碼,用 JavaScript 設定元素的不透明度級別 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 450px;
background-color: gray;
}
</style>
</head>
<body>
<p>Click below to set Opacity.</p>
<button type="button" onclick="display()">Set Opacity</button>
<div id="box">
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
<p>This is a div. This is a div. This is a div. This is a div. This is a div.</p>
</div>
<br>
<script>
function display() {
document.getElementById("box").style.opacity = "0.5";
}
</script>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP