【发布时间】:2017-03-25 18:14:24
【问题描述】:
我正在尝试使用四个按钮(在 Divi Builder 上称为简介),当我单击其中一个时,它将显示一个特定部分 (div) 并隐藏其他三个部分,因此只有一个显示在一次。
这是我目前拥有的:
<!--Photographer script-->
<script>
jQuery(document).ready(function(){
jQuery("#bphotographer").click(function(){
jQuery("#sclient").hide();
jQuery("#sshoot").hide();
jQuery("#sproduct").hide();
});
jQuery("#bphotographer").click(function(){
jQuery("#sphotographer").show();
});
});
</script>
<!--Client script-->
<script>
jQuery(document).ready(function(){
jQuery("#bclient").click(function(){
jQuery("#sphotographer").hide();
jQuery("#sshoot").hide();
jQuery("#sproduct").hide();
});
jQuery("#bclient").click(function(){
jQuery("#sclient").show();
});
});
</script>
<!--Shoot script-->
<script>
jQuery(document).ready(function(){
jQuery("#bshoot").click(function(){
jQuery("#sphotographer").hide();
jQuery("#sclient").hide();
jQuery("#sproduct").hide();
});
jQuery("#bshoot").click(function(){
jQuery("#sshoot").show();
});
});
</script>
<!--Product script-->
<script>
jQuery(document).ready(function(){
jQuery("#bproduct").click(function(){
jQuery("#sphotographer").hide();
jQuery("#sclient").hide();
jQuery("#sshoot").hide();
});
jQuery("#bproduct").click(function(){
jQuery("#sproduct").show();
});
});
</script>
它不是很优化,但它可以工作,并且在 Chrome 的“检查”面板中没有出现任何错误。
大家对如何优化有什么建议吗?
谢谢,
理查德
【问题讨论】:
标签: jquery optimization onclick toggle