火狐下实现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 (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>
相关文章推荐
- JS获取元素属性、样式getComputedStyle()和currentStyle方法兼容性问题
- js获取元素的外链样式的简单实现方法
- 如何用js获取元素样式(get.ComputedStyle()和currentStyle方法)
- JQuery为元素添加样式的实现方法
- php获取数组元素中头一个数组元素值的实现方法
- document.elementFromPoint在IE8下无法稳定获取当前坐标元素的解决方法
- js与jquery获取父级元素,子级元素,兄弟元素的实现方法
- 原生javascript实现获取指定元素下所有后代元素的方法
- jquery绑定事件的方法on中获取当前所在元素及子元素的方式
- 实现在同一方法中获取当前方法中新赋值的session值解决方法
- js获取元素外链样式的方法
- 原生Js获取元素样式属性值的方法
- 解决C#获取鼠标相对当前窗口坐标的实现方法
- 笔记-[1]-获取元素样式值的兼容性问题解决方法。
- JS 获取元素当前的样式信息
- JS之获取样式的简单实现方法(推荐)
- sqlserver中获取当前日期的午夜的时间值的实现方法
- 用currentStyle和getCompusedStyle获取元素的样式
- JQuery为元素添加样式的实现方法