只是添加我使用的确切代码,以供参考。这里是:
var mElem = document.createElement('modern'),
mStyle = mElem.style;
mStyle.backgroundImage = "linear-gradient(left top, #9f9, white)";
mStyle.backgroundImage = "-o-linear-gradient(left top, #9f9, white)";
mStyle.backgroundImage = "-moz-linear-gradient(left top, #9f9, white)";
mStyle.backgroundImage = "-webkit-linear-gradient(left top, #9f9, white)";
mStyle.backgroundImage = "-ms-linear-gradient(left top, #9f9, white)";
mStyle.backgroundImage = "-webkit-gradient(linear, left top, right bottom, from(#9f9), to(white))";
if (mStyle.backgroundImage.indexOf("gradient") == -1) alert("Gradients are not available. Get a better browser and try again.");
它的工作方式与 Modernizr 的实现完全相同,但我只是手动写出了各种渐变,而不是自动完成。对于这么小的特征检测,没有必要自动完成。