问题
HTML 文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>new document</title> <style type="text/css"> .m:before { content: "asdf"; } .m { color: #ff0000; } </style> </head> <body> <div class="m">777</div> <script type="text/javascript"> alert(document.querySelectorAll(".m")[0].currentStyle.content); </script> </body> </html>
在 IE 中,如何取得 "<div class="m">" 的 pseudo element ":before" 的 content 值?
答复
In IE8, it is a mission impossible. 在 IE8, 这大概是不可能的。因为,content 是用来定义 pseudo elements (比如,:before, :after).
currentStyle, 是一般 DOM element 的属性,不能用于pseudo elements。
首先,你就无法得到 pseudo elements (比如说用 getElementById)
到了 IE9,微软也引入支持getComputedStyle(element, pseudo). 才有可能。
连接
原贴:http://bbs.csdn.net/topics/390396139