js控制Style时报错. -问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

js控制Style时报错.

function queryUser(){
    var sty = window.getComputedStyle(document.getElementsByClassName("ddd")[0],"");
    sty.display="block";
}

错误信息:
Uncaught NoModificationAllowedError: Failed to set the 'display' property on 'CSSStyleDeclaration': These styles are computed, and therefore the 'display' property is read-only.

不能这样做吗?
我想做成当事件触发的时候,这个"ddd"才显示出来.

展开
收起
杨冬芳 2016-06-21 14:04:06 2387 0
1 条回答
写回答
取消 提交回答
  • IT从业

    你这是取得它的计算值,
    修改用elem.style.display=

    2019-07-17 19:44:50
    赞同 展开评论 打赏
问答分类:
问答标签:
相关产品:
问答排行榜
最热
最新
相关电子书
更多
在 IoT 设备进行 JavaScript 开发的探索之路
立即下载
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
相关实验场景
更多