Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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
JQuery;切换隐藏显示所有效果!如何预防?_Jquery_Hide_Toggle_Show - Fatal编程技术网

JQuery;切换隐藏显示所有效果!如何预防?

JQuery;切换隐藏显示所有效果!如何预防?,jquery,hide,toggle,show,Jquery,Hide,Toggle,Show,使用我的“添加框”按钮,添加框。 用append!您可以将一些元素精确地附加到框(.togglecontainer)中 使用show more/show les按钮,我希望整个togglecontainer都在下面 该按钮用于切换隐藏和显示 我理解为什么所有具有该类名的容器都开始切换,但我只希望其togglebutton下的容器切换 我试过这个代码,但没有正常工作 $('.togglebtn').toggle(function() { $('.togglecontainer').hide

使用我的“添加框”按钮,添加框。 用append!您可以将一些元素精确地附加到框(.togglecontainer)中 使用show more/show les按钮,我希望整个togglecontainer都在下面 该按钮用于切换隐藏和显示

我理解为什么所有具有该类名的容器都开始切换,但我只希望其togglebutton下的容器切换

我试过这个代码,但没有正常工作

$('.togglebtn').toggle(function() {
    $('.togglecontainer').hide();       
    $(this).html('Show less');
}, function() {
    $('.togglecontainer').show();
    $(this).html('Show more');
});
谁能给我解释一下,帮我解决这个问题? 提前谢谢

这是我的密码; 您需要一个范围选择器。 试试这个:

$('.togglebtn').toggle( function() {              
 $('.togglecontainer', this).hide();                     
 var txt = $(this).html();
 $(this).html((txt=='Show less')?'Show more':'Show less');      
});
编辑:根据OP的输入@jsfiddle更新代码

更新了代码并发布了@Check,如果这是您想要的,请告诉我。

toggle()
不接受两个回调函数


有关如何使用toggle的详细信息,请阅读。

请稍候,toggle不接受两次回调。看到了。谢谢Cybernate,它似乎没有切换可见性,但它确实在html Show less/Show more@Cybernate之间切换。我感谢你的帮助,但它不能正常工作。看@塞伯内特:是的,非常感谢,还有一件事;单击“添加框”时,它会立即以隐藏开始,但单击“添加框”时可以开始“显示”在JSFIDLE更新代码(一个更改为CSS,一个更改为JS)。现在检查一下