通过onclick事件修改元素样式

style代码:

div {
                width: 200px;
                height: 200px;
                background-color: pink;
                margin: 100px auto;
            }
<div></div>

Script代码:

    var div = document.querySelector('div');
            div.onclick = function() {
                this.style.backgroundColor = 'red';
                this.style.width = '100px';
            }

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

插入图片