error - ie strict 模式下不允许分配到只读属性

error - ie strict 模式下不允许分配到只读属性

原因

img.style = 'width:100%;height:100%;display:inline-block;position:relative;z-index:0;'; // strict 模式下不允许分配到只读属性

解决

将css属性拆分开依次设置属性值即可。

img.style.width = '100%';
img.style.height = '100%';
Object.assign(img.style, {
        width: '100%',
        height: '100%',
        display: 'inline-block',
        position: 'relative',
        zIndex: 0,
      });
posted @ 2022-01-27 09:59  zc-lee  阅读(226)  评论(0编辑  收藏  举报