var oP=document.createElement('p');

oP.style.backgroundImage="Inear-gradient(red,tan)"

if( oP.style.backgroundImage ){

  root.classList.add('lineargradients');

}else {

  root.classList.add("no-linear-gradient")

}

 

原理,检测某个具体属性值是否支持,需要把它赋值给对应的属性,再检查浏览器是否还保存这个值,这个过程会改变元素的样式,因此需要一个隐藏的元素

 

函数表示

function testCss(id, value,property){

  var oP=document.createElement('p');

  oP.style[property]=value;

      if( oP.style.backgroundImage ){

         root.classList.add(id);

    return true;

      }else {

       root.classList.add(id);

    return false;

    }

}