<!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>在此示例中,我们将w3-red类添加到活动的折叠栏中(单击按钮并打开内容时)。</p>
<button onclick="myFunction('Demo1')" class="w3-button w3-block w3-black w3-left-align">打开第一节</button>
<div id="Demo1" class="w3-hide w3-container">
<p>一些文字..</p>
</div>
<button onclick="myFunction('Demo2')" class="w3-button w3-block w3-black w3-left-align">打开第二节</button>
<div id="Demo2" class="w3-hide w3-container">
<p>其他一些文字..</p>
</div>
</div>
<script>
function myFunction(id) {
var x = document.getElementById(id);
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
x.previousElementSibling.className =
x.previousElementSibling.className.replace("w3-black", "w3-red");
} else {
x.className = x.className.replace(" w3-show", "");
x.previousElementSibling.className =