我想檢測瀏覽器是否支持使用javascript的CSS屬性(特別是是否支持「filter」)?我該怎麼做?如何檢測瀏覽器是否支持使用javascript的css屬性?
我嘗試以下功能
supportsCssStyle: function (prop) {
var div = document.createElement('div'),
vendors = 'Khtml Ms O Moz Webkit'.split(' '),
len = vendors.length;
if (prop in div.style) return true;
prop = prop.replace(/^[a-z]/, function (val) {
return val.toUpperCase();
});
while (len--) {
if (vendors[len] + prop in div.style) {
// browser supports box-shadow. Do what you need.
// Or use a bang (!) to test if the browser doesn't.
return true;
}
}
return false;
},
,但它不工作
聽起來像http://stackoverflow.com/questions/16189905/can-i-detect -whether-css-filter-effects-are-supported – nuway
我不想使用Modernizr – Jasmine
什麼不行?你的代碼適合我。 – Oriol