These styles are computed, and therefore the ‘visibility‘ property is read-only.“

These styles are computed, and therefore the ‘visibility’ property is read-only."报错原因及处理方法

  1. 要实现的样式:点击“关注公众号”,弹出遮罩层和二维码图片,此时我的遮罩层可以实现toggle样式,(点击弹出遮罩层,在点击隐藏遮罩层效果)。问题在于图片不显示。↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓,我开始看报错,他说,visibility是只读属性,不能修改。这很奇怪,因为这个属性是一定可以修改的,于是我开始看我的代码
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“

  2. 我在style里面找到了对应元素的visibility属性(一般不建议用visibility,可以使用display,图片上有解释,看不懂的可以问度娘)
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“

  3. 后来我在script的methods中找到对应的方法,我在这里用到了一个之前没有用过的 获取元素属性的方法,而这个 document . defaultView. getComputedStyle()方法,仅仅能用来获取属性值,但并不能用于修改属性值,所以在错误提示中显示read-only
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“

  4. 这个时候我换了一个方法,元素.style.属性,这个时候需要注意的一个点是,该方法仅能修改内嵌式样式属性,所以这个时候你可以把要修改的属性放在对应元素的style=“”里面。下面是修改后的
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“
    These styles are computed, and therefore the ‘visibility‘ property is read-only.“

  5. 给你们看看改完之后的效果

These styles are computed, and therefore the ‘visibility‘ property is read-only.“

上一篇:Vue之回顾总结-常用点


下一篇:微信小程序-渲染层网络层错误