Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 jQuery切换更多按钮切换多个div_Javascript_Jquery_Toggle - Fatal编程技术网

Javascript jQuery切换更多按钮切换多个div

Javascript jQuery切换更多按钮切换多个div,javascript,jquery,toggle,Javascript,Jquery,Toggle,我已经为切换按钮编写了jquery $(document).ready(function(){ /* Needs to be re-written for multiple questions */ $(".full_question").hide(); $('.question a').after('<a class="show_full_question" href="#">more</a>'); $('.show_full_ques

我已经为切换按钮编写了jquery

$(document).ready(function(){
    /* Needs to be re-written for multiple questions */
    $(".full_question").hide();
    $('.question a').after('<a class="show_full_question" href="#">more</a>');

    $('.show_full_question').click(function() {
    var el = this;
        $(".full_question").toggle(function() {
            $(el).text($(el).text() == 'less' ? 'more' : 'less');
            $(el).toggleClass("hide_full_question");
        });
    });
});
$(文档).ready(函数(){
/*需要重新编写多个问题*/
$(“.full_question”).hide();
$('问题a')。在('')之后;
$('.show_full_question')。单击(函数(){
var el=这个;
$(“.full_question”).toggle(函数(){
$(el).text($(el).text()=='less'?'more':'less');
$(el).toggleClass(“隐藏完整问题”);
});
});
});
它在整个问题宽度和部分宽度之间切换。但当点击时,它会切换页面上的所有问题。我怎样才能得到它呢

我知道这和美元有关,但我不知道它去了哪里。。。如果有必要,我不介意更改html

html是

<h3 class="question">
  <a href="#">What size is the circumference of the earth? I don't really know what it is! Help me! What size is the...
    <span class="full_question"> circumference of the earth? I really don't know!</span>
  </a>
</h3>

问题是
$(“.full\u question”)。toggle()
将使用
full\u question
类切换所有元素。您需要以某种方式将当前单击的元素与适当的完整问题链接起来

由于在同一父项下有一个
full_question
和一个
show_full_question
按钮,因此可以使用jQuery获取父项并查找要切换的问题:

$(this).parent().find(".full_question").toggle()
如果您确定HTML结构不会改变,您还可以执行以下操作:

$(this.previousSibling.childNodes[1]).toggle()

这里有一个。你能不能也添加html代码(或一个代码片段)是的,为问题发布html