ljchow 发表于 2010-6-4 17:22:36

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>

ljchow 发表于 2010-6-4 18:51:39

贴到代码里
<!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>

ljchow 发表于 2010-6-4 18:54:07

上面是不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>

ljchow 发表于 2010-6-8 19:50:26

请查看答案
http://bbs.51js.com/viewthread.php?tid=87251

sggtong 发表于 2010-6-24 13:59:41

学习到了 :loveliness:
页: [1]
查看完整版本: Firefox下当"opacity: 0.6;"写在css类中,js读不到值