我是编程新手,并试图简化一些 jquery/javascript 代码,但我没有取得太大的成功。我尝试调整此处找到的解决方案:jQuery Simplify
...但同样,没有成功。
这是我的jQuery代码:
<script>
$(document).ready(function(){
$("#hide01").click(function(){
$(".content01").hide();
});
$("#show01").click(function(){
$("p").hide();
$(".content01").show();
});
$("#hide02").click(function(){
$(".content02").hide();
});
$("#show02").click(function(){
$("p").hide();
$(".content02").show();
});
});
</script>
和 HTML:
<button id="hide01">Hide</button>
<button id="show01">Show</button>
<button id="hide02">Hide</button>
<button id="show02">Show</button>
<p class="content01">Content 01</p>
<p class="content02">Content 02</p>
该解决方案有效,但我需要 40 个按钮/内容块...
任何人都可以帮忙吗?谢谢!