我在寻找更聪明的方法来隐藏和显示多个元素。 我现在的解决方案是为每个要显示的元素创建一个单独的脚本,只需单击一个按钮即可。jquery隐藏显示多个div
<a class="pure-button pure-button-primary" type='button' id='hideshow1'
value='hide/show' >Show it1 !</a>
<div id='content1' style="display:none">
lorem ipsum
</div>
<a class="pure-button pure-button-primary" type='button' id='hideshow2'
value='hide/show' >Show 2 </a>
<div id='content2' style="display:none">
lorem ipsum
</div>
这是脚本的一部分:
<script>
jQuery(document).ready(function(){
jQuery('#hideshow1').on('click', function(event) {
jQuery('#content1').toggle('hide');
});
});
</script>
<script>
jQuery(document).ready(function(){
jQuery('#hideshow2').on('click', function(event) {
jQuery('#content2').toggle('hide');
});
});
</script>
这样完美的作品,但我认为必须有一个更聪明的方法。任何人都可以给我一个线索如何让它变得更聪明?
我试过这个建议,它对我很好。感谢您向我展示此内容 – Richard