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

来源:互联网 发布:中超后卫数据 编辑:程序博客网 时间:2024/06/04 20:07
<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>