JavaScript
var an = document.getElementById('按钮元素id');
var tee = document.getElementById('要显示或的元素id');
//这里设置元素默认隐藏
tee.style.display = 'none';
an.onclick = function () {
if (tee.style.display == 'block') {
tee.style.display = 'none';
an.innerHTML = "≡";
} else {
tee.style.display = 'block';
an.innerHTML = "X";
};
};
html示例
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>网页名称</title>
<style>
</style>
</head>
<body>
<a id="t">X</a>
<h1 id="o">1111111111111111111111111111111</h1>
<script>
var an = document.getElementById('t');
var tee = document.getElementById('o');
tee.style.display = 'none';
an.onclick = function () {
if (tee.style.display == 'block') {
tee.style.display = 'none';
an.innerHTML = "≡";
} else {
tee.style.display = 'block';
an.innerHTML = "X";
};
};
</script>
</body>