SOURCE

console 命令行工具 X clear

                    
>
console
function switch1() {
    console.log(document.getElementById('div').style.transform)
    if (document.getElementById('div').style.transform === "scale(0.5)") {
        document.getElementById('div').style.transform = ""
    } else {
        document.getElementById('div').style.transform = "scale(0.5)"
    }
}
function switch2() {
    console.log(document.getElementById('span').style.right)
    if (document.getElementById('span').style.right === '50px') {
        document.getElementById('span').style.right = 0
    } else {
        document.getElementById('span').style.left = '50px'
    }
}
<div id="div">
    <div id="span"></div>
</div>
<button onclick="switch1()">switch1</button>
<button onclick="switch2()">switch2</button>
#div{
    width: 100px;
    height: 100px;
    background: yellow;
    position: relative
}
#span{
    position: absolute;
    top: 20px;
    left: 0;
    width: 3px;
    height: 3px;
    background: red;
}