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

标签 javascript jquery html

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

我已经开始构建一个示例,我遇到的问题是两行当前都是可见的,当我单击 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/

相关文章:

javascript - 鼠标悬停 UL 子节点不正确

javascript - 在顶部的元素框上滚动设置背景颜色

javascript - 如何在 div 上应用 maskmoney?

jquery - 如何使用 css 选择器排除内部 webelement?

javascript - Vue - 动画与使用 Click 的普通 javascript 实现的区别

javascript - 可扩展列表形式的复选框/单选按钮无响应

javascript - 如何将jsp数组发送到Ajax?

javascript - jquery 脚本对我不起作用

html.erb - 如何用空 div 填充最后一行

Javascript 石头、剪刀、布游戏。我的代码有什么问题吗?