JavaScript 显示隐藏div js显示或隐藏div
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| const controlDiv = document.createElement('div');
const showHideBtn = document.createElement('button');
showHideBtn.innerText = '隐藏';
showHideBtn.onclick = function () { if (showHideBtn.innerText === '隐藏') { controlDiv.style.display = 'none'; showHideBtn.innerText = '显示'; } else if (showHideBtn.innerText === '显示') { controlDiv.style.display = 'block'; showHideBtn.innerText = '隐藏'; } }
|