美文网首页
getStyleFunction

getStyleFunction

作者: Jadon7 | 来源:发表于2018-10-08 06:01 被阅读0次
<!DOCTYPE html>
<html>
<head>
    <title>getStyleFunction</title>
</head>
<script type="text/javascript">
    function getStyle(obj,name)
    {
        if (obj.currentStyle)
        {
            return obj.currentStyle[name];
        }
        else
        {
            return getComputedStyle(obj,false)[name];
        }
    }
    window.onload=function()
    {
        var oDiv=document.getElementById('div1');
        alert(getStyle(oDiv,'height'));
    }
</script>
<style type="text/css">
    #div1{
        width: 100px;
        height: 100px;
        background-color: green;
    }
</style>
<body>
    <div id="div1"></div>
</body>
</html>

相关文章

网友评论

      本文标题:getStyleFunction

      本文链接:https://www.haomeiwen.com/subject/xbqdaftx.html