<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>
FF下实现currentStyle方法
最新推荐文章于 2021-08-04 01:15:30 发布
本文介绍了一种利用JavaScript和CSS结合的方式来自定义获取元素样式的技巧。通过修改JavaScript原型链,使得可以轻松地获取到元素的第一行颜色样式。同时,通过实际的HTML示例演示了如何使用这种方式来获取具体的样式。
165

被折叠的 条评论
为什么被折叠?



