javascript - js控制Style时报错.

查看:357
本文介绍了javascript - 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"才显示出来.

解决方案

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

这篇关于javascript - js控制Style时报错.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆