Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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_Jquery_Html_Css - Fatal编程技术网

Javascript 显示表格行中的第一行,然后单击展开或折叠并更改+;签名对签名

Javascript 显示表格行中的第一行,然后单击展开或折叠并更改+;签名对签名,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这个问题类似于。 @thirtydot提供的答案是。 我的问题是,当线条展开时,如何将+sign改为-sign,当线条折叠时,如何将-sign改为+sign $('.expand')。每个(函数(){ var reducedHeight=$(this).height(); $(this.css('height','auto'); var fullHeight=$(this).height(); $(此).height(还原高度); $(此).data('reducedHeight',reduc

这个问题类似于。 @thirtydot提供的答案是。 我的问题是,当线条展开时,如何将+sign改为-sign,当线条折叠时,如何将-sign改为+sign

$('.expand')。每个(函数(){
var reducedHeight=$(this).height();
$(this.css('height','auto');
var fullHeight=$(this).height();
$(此).height(还原高度);
$(此).data('reducedHeight',reducedHeight);
$(此).data('fullHeight',fullHeight);
})。单击(函数(){
$(this).animate({height:$(this).height()==$(this.data('reducedHeight')?$(this.data('fullHeight'):$(this.data('reducedHeight')))},500);
});
。展开{
边框:1px纯红;
高度:1米;
填充:2px;
溢出:隐藏
}

[+]Lorem ipsum door sit amet,是一位杰出的领导者。但尤伊斯莫德、乌尔特里斯、毛里斯·杜尔皮斯发酵酒、多洛尔葡萄和莱科斯葡萄。莫比·ac·波苏尔·奥奇。阿利奎姆·埃拉特·帕特。在accumsan,佩伦特斯式的会议。Maecenas sem augue,placerat commodo convallis non,commodo vel elit。前庭门静脉曲张或胎动舌苔。梅塞纳斯统治着拉奥里特·苏西比特。不要把布朗迪特当成奥古斯特·亨德雷特·维内纳提斯。尼布·伊普苏姆,康瓦利斯·马蒂斯·伊库利斯,卢克图斯·阿卡里斯。莫比·康莫多·索利西图因同侧,前庭在同侧。

你可以用多种方法来做。这是一个:

$('.expand')。每个(函数(){
var reducedHeight=$(this).height();
$(this.css('height','auto');
var fullHeight=$(this).height();
$(此).height(还原高度);
$(此).data('reducedHeight',reducedHeight);
$(此).data('fullHeight',fullHeight);
})。单击(函数(){
$(this).animate({height:$(this).height()==$(this.data('reducedHeight')?$(this.data('fullHeight'):$(this.data('reducedHeight')))},500);
$(this).find('.expand_-sign,.collapse_-sign').toggleClass('hidden');
});
。展开{
边框:1px纯红;
高度:1米;
填充:2px;
溢出:隐藏
}
.隐藏{
显示:无;
}

[+][-]Lorem ipsum door sit amet,奉献精英。但尤伊斯莫德、乌尔特里斯、毛里斯·杜尔皮斯发酵酒、多洛尔葡萄和莱科斯葡萄。莫比·ac·波苏尔·奥奇。阿利奎姆·埃拉特·帕特。在accumsan,佩伦特斯式的会议。Maecenas sem augue,placerat commodo convallis non,commodo vel elit。前庭门静脉曲张或胎动舌苔。梅塞纳斯统治着拉奥里特·苏西比特。不要把布朗迪特当成奥古斯特·亨德雷特·维内纳提斯。尼布·伊普苏姆,康瓦利斯·马蒂斯·伊库利斯,卢克图斯·阿卡里斯。莫比·康莫多·索利西图因同侧,前庭在同侧。

就像前面提到的,有很多不同的方法可以做到这一点

您可以使用CSS:

.expand {
    border: 1px solid red;
    height: 1em;
    padding: 2px;
    overflow: hidden    
}

.expand a {
    width: 25px;
    text-align: center;
    display: inline-block;
}

.expand a:after {
    content: '[+]';
}

.expand a.open:after {
    content: '[-]';  
}

.hidden {
 display: none;
}
然后只需添加/删除该类:

$('.expand').each(function(){
    var reducedHeight = $(this).height();
    $(this).css('height', 'auto');
    var fullHeight = $(this).height();
    $(this).height(reducedHeight);

    $(this).data('reducedHeight', reducedHeight);
    $(this).data('fullHeight', fullHeight);
}).click(function() {
    // Get the <a>, check if it has the open class
    // if it does, remove it, if it doesn't, add it
    var $sign = $(this).find('a');
    if($sign.hasClass('open')){
        $sign.removeClass('open');
    }else{
        $sign.addClass('open');
    }
    $(this).animate({height: $(this).height() == $(this).data('reducedHeight') ? $(this).data('fullHeight') : $(this).data('reducedHeight')}, 500);
});
$('.expand')。每个(函数(){
var reducedHeight=$(this).height();
$(this.css('height','auto');
var fullHeight=$(this).height();
$(此).height(还原高度);
$(此).data('reducedHeight',reducedHeight);
$(此).data('fullHeight',fullHeight);
})。单击(函数(){

//获取。

我不知道我做错了什么,但它不起作用:-不是你,是我:)我忘记了“内容”必须与伪元素一起使用,如:before和:after。我用一个关于我试图完成的工作的示例更新了我的答案。