如何使用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>热门推荐
4 十月简短祝福语
10 女神节日简短祝福语大全
11 牛年除夕祝福语简短的
12 爱情祝福语大全 简短实际
13 婚礼祝福语简短精辟的
14 聚餐会祝福语简短
15 孙子结婚祝福语大全简短
16 老师祝福语简短100字
17 好朋友夫妻祝福语简短
18 国庆简短幽默祝福语