您的位置:首页 > Web前端 > CSS

火狐下实现currentStyle方法(获取当前元素样式)

2011-07-14 11:30 716 查看
<script type="text/javascript">

(function (bool) {

//严重感谢M2前辈

    if (bool) {

        HTMLElement.prototype.__defineGetter__("currentStyle", function () {

        //getComputedStyle方法参数一是目标对象,参数二是具体属性。。。把注释对换下就知道了。。

            //return this.ownerDocument.defaultView.getComputedStyle(this, ":first-line");

            return this.ownerDocument.defaultView.getComputedStyle(this, null);

        });

    }

})(/Firefox/.test(window.navigator.userAgent));

</script>

<style type="text/css">

div {

    color:#000000;

}

div:first-line {

    color:#0000FF;

}

</style>

<div onclick="alert(this.currentStyle.color)">DIV对象<br />第二行</div> 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  function div null