使用 conditional comment 來判斷 IE 的版本。嗯,是早早有人提出,但沒有認真看代碼。昨天剛好在看 CSS3 PIE 的時候看到,覺得是不是不靠譜。今天看到 Paul Irish 也提起,那么,推薦一下吧。這是作者博客上寫的:
// UPDATE: Now using Live NodeList idea from @jdalton
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
注意一下這個 while 語句。是我覺得最有趣的。對于逗號操作符。我也不熟悉,還只是停留在像變量定義的用法上。比如:
var obj = {
a: 'b',
c: 'd',
e: 'f'
}
新聞熱點
疑難解答