js操作css

-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7));
如何用js操作呢,
dom.style.webkitLinearGradient = '(bottom,rgba(0,0,0,0),rgba(0,0,0,.7))';  不对
dom.style.webkitLineargradient = '(bottom,rgba(0,0,0,0),rgba(0,0,0,.7))';  也不对
阅读 2.6k
3 个回答
dom.style.background='-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7))'

这样,你见过css那样写的吗

linear-gradient是一个颜色值,不是属性,你应该在CSS中这样写比如说background:-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7));,JS中dom.style.background="-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7))";

'-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7))'这一整个字符串是一个属性值,所以使用dom操作的话应该是这样:

dom.style.属性名 = '-webkit-linear-gradient( bottom,rgba(0,0,0,0),rgba(0,0,0,.7))';
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题