Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想一次打开一个显示/隐藏加减表_Javascript_Html_Css_Bootstrap 4 - Fatal编程技术网

Javascript 我想一次打开一个显示/隐藏加减表

Javascript 我想一次打开一个显示/隐藏加减表,javascript,html,css,bootstrap-4,Javascript,Html,Css,Bootstrap 4,$(文档).ready(函数(){ $(“#t1”).hide();//默认情况下隐藏表 $(“#close”).hide();//如果一次只想显示一个按钮,请同时隐藏减号按钮 $('#sp1')。在('click',function(){//上单击加号按钮时 $(“#t1”).show(); $(“#sp1”).hide();//现在需要隐藏加号按钮 $(“#关闭”).show();//然后显示减号按钮 }); $('#close')。在('click',function(){ $(“#t1”

$(文档).ready(函数(){
$(“#t1”).hide();//默认情况下隐藏表
$(“#close”).hide();//如果一次只想显示一个按钮,请同时隐藏减号按钮
$('#sp1')。在('click',function(){//上单击加号按钮时
$(“#t1”).show();
$(“#sp1”).hide();//现在需要隐藏加号按钮
$(“#关闭”).show();//然后显示减号按钮
});
$('#close')。在('click',function(){
$(“#t1”).hide();//隐藏表
$(“#关闭”).hide();//隐藏减去btn
$(“#sp1”).show();//显示加号按钮
});
});
$(文档).ready(函数(){
$(“#t2”).hide();//默认情况下隐藏表
$('#sp2')。在('click',function()上{
切换按钮(真);
$(“#t2”).show();
});
$('#close2')。在('click',function()上{
切换按钮(错误)
$(“#t2”).hide();
});
功能切换按钮(显示){
如果(显示){
$(“#sp2”).hide();
$(“#close2”).show();
}否则{
$(“#sp2”).show();
$(“#close2”).hide();
}
}
});

主标题
分标题1
分标题2
子标题
一排
第2排
儿童头像2
第3排
第4排

因为使用Bootstrap,您应该真正考虑如何使代码更可重用(并且稍微有点可读性,尽管在大多数情况下您都做得很好)。我重写了一些代码只是为了演示这个概念(在显示单击的元素之前隐藏所有元素)。。。我太懒了,没有试着通过解析你的来把它全部理清

$(文档).ready(函数(){
$(“.allcontent”).hide();//默认情况下隐藏表
$(“.hide”).hide();//如果一次只想显示一个按钮,请同时隐藏减号按钮
$('.show')。在('click',function()上{
$('.allcontent').hide();
$('.show').show();
$('.hide').hide();
$(this.parent().find('.show').hide();
$(this.parent().find('.hide').show();
$(this.parent().parent().find('.allcontent').show();
});
$('.hide')。在('click',function()上{
$(this.parent().find('.show').show();
$(this.parent().find('.hide').hide();
$(this.parent().parent().find('.allcontent').hide();
});
});

+
-
一排
第2排
+
-
第3排
第4排

因为使用Bootstrap,您应该真正考虑如何使代码更可重用(并且稍微有点可读性,尽管在大多数情况下您都做得很好)。我重写了一些代码只是为了演示这个概念(在显示单击的元素之前隐藏所有元素)。。。我太懒了,没有试着通过解析你的来把它全部理清

$(文档).ready(函数(){
$(“.allcontent”).hide();//默认情况下隐藏表
$(“.hide”).hide();//如果一次只想显示一个按钮,请同时隐藏减号按钮
$('.show')。在('click',function()上{
$('.allcontent').hide();
$('.show').show();
$('.hide').hide();
$(this.parent().find('.show').hide();
$(this.parent().find('.hide').show();
$(this.parent().parent().find('.allcontent').show();
});
$('.hide')。在('click',function()上{
$(this.parent().find('.show').show();
$(this.parent().find('.hide').hide();
$(this.parent().parent().find('.allcontent').hide();
});
});

+
-
一排
第2排
+
-
第3排
第4排

您的意思是只想要一张t表吗