<!DOCTYPE html>
<html>
<head>
<title>W3.CSS(w3cschool.cn)</title>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="UTF-8">
<link rel="stylesheet" href="https://7npmedia.w3cschool.cn/w3.css">
</head>
<body>
<div class="w3-container">
<h2>折叠栏</h2>
<p>带有列表的折叠栏:</p>
<button onclick="myFunction('Demo1')" class="w3-button w3-block w3-left-align">
折叠栏</button>
<div id="Demo1" class="w3-hide">
<ul class="w3-ul">
<li>孙子</li>
<li>孔子</li>
<li>老子</li>
</ul>
</div>
</div>
<script>
function myFunction(id) {
var x = document.getElementById(id);
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
} else {
x.className = x.className.replace(" w3-show", "");
}
}
</script>