/* 点击切换显示隐藏 */ var box = document.getElementById('box'); var btn = box.children[0]; var content = box.children[1]; // window.getComputedStyle(element, pseudoElement) //element: 必需,要获取样式的元素。可以获取选定元素的样式 var contentStyle = window.getComputedStyle(box.children[1]); console.log(contentStyle,'contentStyle') btn.onclick = function() { btn.style.cursor = "pointer"; //鼠标移入按钮形状 // content.style.display = contentStyle.display == "none" ? "block" : "none"; if(contentStyle.display == "none"){ content.style.display = "block"; }else{ content.style.display = "none"; } }