本文介绍了如何将此脚本代码修改为最小行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
       var hide1 = true;
       var hide2 = true;
       var hide3 = true;

       function hideColumn1(tableId, colIndex) {
           var table = document.getElementById(tableId);

           if (table != null) {
               for (i = 0; i < table.rows.length; i++) {
                   if (hide1)
                       table.rows[i].cells[colIndex - 1].style.display = 'none';
                   else
                       table.rows[i].cells[colIndex - 1].style.display = '';
               }
               hide1 = !hide1;
           }
       }
       function hideColumn2(tableId, colIndex) {
           var table = document.getElementById(tableId);

           if (table != null) {
               for (i = 0; i < table.rows.length; i++) {
                   if (hide2)
                       table.rows[i].cells[colIndex - 1].style.display = 'none';
                   else
                       table.rows[i].cells[colIndex - 1].style.display = '';
               }
               hide2 = !hide2;
           }
       }
       function hideColumn3(tableId, colIndex) {
           var table = document.getElementById(tableId);

           if (table != null) {
               for (i = 0; i < table.rows.length; i++) {
                   if (hide3)
                       table.rows[i].cells[colIndex - 1].style.display = 'none';
                   else
                       table.rows[i].cells[colIndex - 1].style.display = '';
               }
               hide3 = !hide3;
           }
       }



   </script>







在这个脚本中我使用3方法进行同样的工作。我找到了最好的解决方案。 plz给我正确的方法来完成这个脚本。




in this script i use 3 method for same work . i find the best solution . plz give me right way to complete this script.

推荐答案

function hideColumn1(e,t){var n=document.getElementById(e);if(n!=null){for(i=0;i<n.rows.length;i++){if(hide1)n.rows[i].cells[t-1].style.display="none";else n.rows[i].cells[t-1].style.display=""}hide1=!hide1}}function hideColumn2(e,t){var n=document.getElementById(e);if(n!=null){for(i=0;i<n.rows.length;i++){if(hide2)n.rows[i].cells[t-1].style.display="none";else n.rows[i].cells[t-1].style.display=""}hide2=!hide2}}function hideColumn3(e,t){var n=document.getElementById(e);if(n!=null){for(i=0;i<n.rows.length;i++){if(hide3)n.rows[i].cells[t-1].style.display="none";else n.rows[i].cells[t-1].style.display=""}hide3=!hide3}}var hide1=true;var hide2=true;var hide3=true





您可以尝试以下工具: []和 []。



<script type="text/javascript">
    var hide1 = true;
    var hide2 = true;
    var hide3 = true;

    function hideColumn1(tableId, colIndex,hideType,ColumnValue) {
        var table = document.getElementById(tableId);

        if (table != null) {
            for (i = 0; i < table.rows.length; i++) {
                if (hideType)
                    table.rows[i].cells[colIndex - 1].style.display = 'none';
                else
                    table.rows[i].cells[colIndex - 1].style.display = '';
            }
            if(ColumnValue == "Column1")
            {
                hide1 = !hideType;
            }
            if(ColumnValue == "Column2")
            {
                hide2 = !hideType;
            }
            if(ColumnValue == "Column3")
            {
                hide3 = !hideType;
            }
        }
    }


</script>





您只是隐藏列并更新变量hide1,hide2,hide3。所以我刚更新了你的功能。

1.在你的函数中加入更多参数。

2. hidetype传递变量的当前状态(true / false)

3. columnValue传递你的coumn id。你写的差异功能。

4.最后检查列值并根据设置变量状态。



希望它会有所帮助。



you are just hiding the column and updating the variable hide1,hide2,hide3. so i just updated the your function .
1. added to more parameter into your function.
2. hidetype pass the current status of variable (true/false)
3. columnValue pass the you coumn id. fot that you were written diff function.
4. at last check the column value and on the basis of that set the variable status.

hope it will be help.


这篇关于如何将此脚本代码修改为最小行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:25