gpt4 book ai didi

javascript - 一次扩展一个 div

转载 作者:行者123 更新时间:2023-11-30 13:27:44 26 4
gpt4 key购买 nike

http://jsfiddle.net/Hvvw7/

当我点击“查看更多”时,它会展开所有的 div。应该怎么做才能只展开对应的div?

$(document).ready(function(){
var rowsshown = 2;
var rowheight = 1.2; // line height in 'em'
var ht = (rowsshown * rowheight) - .5; // subtracting the .5 prevents the top of the next line from showing
$('.info')
.css({'overflow':'hidden','line-height' : rowheight + 'em','height': ht + 'em' });
});
$('.aaa').click(function(){

if ( $(".info").css('height') == 'auto') {
$('.info').css('height', ht + 'em');
} else {
$('.info').css('height','auto');
$(this).hide();
}
});

最佳答案

您可以使用 $(this).prev('div') 作为点击事件中的选择器,而不是 $(".info")选择使用 info 类的每个元素。在这个 fiddle 中看到:http://jsfiddle.net/Hvvw7/3/

通常我不喜欢这个解决方案,但您的 HTML 对您尝试执行的操作有一种奇怪的结构,因此它可能是您的最佳选择。

关于javascript - 一次扩展一个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897120/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com