gpt4 book ai didi

javascript - 展开表格行以显示更多数据

转载 作者:行者123 更新时间:2023-11-30 12:56:33 24 4
gpt4 key购买 nike

我有一个表格,我想做的是在其中一列中有一个按钮/链接,一旦单击它,另一行就会出现在下面,其中包含更多信息。

我已经开始构建一个示例,我遇到的问题是两行当前都是可见的,当我单击 View 链接时,两行都向下滑动。我实际上想做的是让一行可见,然后当我单击 View 时,第二行变为可见。

这是我的演示链接:http://jsfiddle.net/leest/Jgrja/

这是我的代码

HTML

 <table class="">
<!-- Table heading -->
<thead>
<tr>
<th>Rendering eng.</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Eng. vers.</th>
<th>CSS grade</th>
</tr>
</thead>
<!-- // Table heading END -->

<!-- Table body -->
<tbody>
<!-- Table row -->
<tr class="gradeX">
<td>Trident</td>
<td>Internet Explorer 4.0</td>
<td>Win 95+</td>
<td class="center">4</td>
<td class="center"><a href="#" class="show_hide" rel="#slidingDiv">View</a><br /></td>
</tr>
<div id="slidingDiv">
<tr>
<td>Trident</td>
<td>Internet Explorer 4.0</td>
<td>Win 95+</td>
<td class="center">4</td>
<td class="center">X</td>
</div>
</tr>

</tbody>

</table>

JavaScript 代码

    $(document).ready(function(){


$('.show_hide').showHide({
speed: 1000, // speed you want the toggle to happen
easing: '',
changeText: 1, // if you dont want the button text to change, set this to 0
showText: 'View',// the button text to show when a div is closed
hideText: 'Close' // the button text to show when a div is open

});


});


(function ($) {
$.fn.showHide = function (options) {

//default vars for the plugin
var defaults = {
speed: 1000,
easing: '',
changeText: 0,
showText: 'Show',
hideText: 'Hide'

};
var options = $.extend(defaults, options);

$(this).click(function () {

$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which div id to toggle
var toggleDiv = $(this).attr('rel');
using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText);
}
});

return false;

});

};
})(jQuery);

我不确定我是否采取了正确的方式,因此我们将不胜感激任何建议。

谢谢

最佳答案

不要将行包裹在 div 中。尝试为实际的 <tr> 设置动画你想显示/隐藏: http://jsfiddle.net/Jgrja/1/

关于javascript - 展开表格行以显示更多数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18914899/

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