当前位置:首页 > Web开发 > 正文

以改变此元素的不透明度

2024-03-31 Web开发

CSS 属性opacity,规定不透明度,从 0.0(完全透明)到1.0(完全不透明)

opacity: value| inherit; 规定

<!DOCTYPE html> <html> <head>

<script> function ChangeOpacity(x) { // 返回当选选项的文本 var opacity=x.options[x.selectedIndex].text; var el=document.getElementById("p1"); if (el.style.opacity!==undefined) {el.style.opacity=opacity;} else {alert("Your browser doesn‘t support this example!");} } </script>

</head> <body> <p id="p1">请从下面的例子中选择一个值,以转变此元素的不透明度。</p>
<!--size 用来设置选择框的长度 --> <select onchange="ChangeOpacity(this);" size="5"> <option />0 <option />0.2 <option />0.5 <option />0.8 <option selected="selected" />1 </select> </body> </html>

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32391.html