开发者社区 问答 正文

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 2750 分享 版权
1 条回答
写回答
取消 提交回答
  • IT从业

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

    2019-07-17 19:44:50
    赞同 展开评论
问答分类:
问答标签:
问答地址: