Firefox下当"opacity: 0.6;"写在css类中,js读不到值
Firefox下当"opacity: 0.6;"写在css类中,js读不到值;而写到style="opacity: 0.6;"中,却可以取到。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
window.onload = function() {
alert(document.getElementById("divObj").style.opacity);
}
</script>
<style type="text/css">
.div
{
position: absolute;
border: solid 1px #849BCA;
left: 50px;
top: 100px;
width: 100px;
height: 80px;
background-color: #DBE4ED;
white-space: nowrap;
overflow: hidden;
filter: alpha(opacity=60);
opacity: 0.6;
}
</style>
</head>
<body>
<div id="divObj" class="div" style="">
</div>
</body>
</html> 贴到代码里
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
window.onload = function() {
alert(document.getElementById("divObj").style.opacity);
}
</script>
<style type="text/css">
.div
{
position: absolute;
border: solid 1px #849BCA;
left: 50px;
top: 100px;
width: 100px;
height: 80px;
background-color: #DBE4ED;
white-space: nowrap;
overflow: hidden;
filter: alpha(opacity=60);
opacity: 0.6;
}
</style>
</head>
<body>
<div id="divObj" class="div" style="">
</div>
</body>
</html> 上面是不work的,这个就work了,我只是style="opacity: 0.6;",放到了style里而已。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
window.onload = function() {
alert(document.getElementById("divObj").style.opacity);
}
</script>
<style type="text/css">
.div
{
position: absolute;
border: solid 1px #849BCA;
left: 50px;
top: 100px;
width: 100px;
height: 80px;
background-color: #DBE4ED;
white-space: nowrap;
overflow: hidden;
filter: alpha(opacity=60);
}
</style>
</head>
<body>
<div id="divObj" class="div" style="opacity: 0.6;">
</div>
</body>
</html> 请查看答案
http://bbs.51js.com/viewthread.php?tid=87251 学习到了 :loveliness:
页:
[1]