我从w3school找到一个示例程序,并且我设法编辑它。但问题是,它太耗费代码,我想要的是这个代码的简短版本。可能吗? (我试图把该div在PHP包括,我使用一个单一的切换功能和多个按钮,但一旦我点击一个按钮所有的div显示)。jquery切换多个ID
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#p1").hide();
$("#p2").hide();
$("#p3").hide();
$("#p4").hide();
$("#button1").click(function(){
$("#p1").toggle();
});
$("#button2").click(function(){
$("#p2").toggle();
});
$("#button3").click(function(){
$("#p3").toggle();
});
$("#button4").click(function(){
$("#p4").toggle();
});
});
</script>
</head>
<body>
<div id="p1">
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</div>
<button id="button1">Toggle</button>
<br>
<br>
<br>
<div id="p2">
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</div>
<button id="button2">Toggle</button>
<br>
<br>
<br>
<div id="p3">
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</div>
<button id="button3">Toggle</button>
<br>
<br>
<br>
<div id="p4">
<p>This is a paragraph with little content.</p>
<p>This is another small paragraph.</p>
</div>
<button id="button4">Toggle</button>
<br>
<br>
<br>
</body>
</html>
你的代码工作完美!但在我的实际代码没有工作..错误是在我的代码.. –
我想你没有**