突然发现IE8不能使用querySelectorAll,实在拿IE没办法,只好用以下手段强制使用IE8模式,于是选择器终于回到正轨。
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<!doctype html> <html dir="ltr" lang="zh-CN"> <head> <meta charset="utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>强制在IE8模式下运行 by 司徒正美</title> <script type="text/javascript"> window.onload = function(){ alert(document.documentMode) } </script> </head> <body > </body> </html>
运行代码
注意,它是不能通过编程方式实现,因为我们加入脚本时,渲染模式已经决定,不能像样式、属性那样可以重设。