[英]Passing multiple variables to a javascript function?
I have a big table of info which can get a bit overwhelming. 我有一个很大的信息表,可能有点压倒性的。 I currently have buttons to hide or show certain columns to make it easier to find what you need.
我目前有按钮隐藏或显示某些列,以便更容易找到您需要的。 I use this code to show/hide.
我用这段代码来显示/隐藏。
<script type="text/javascript" charset="utf-8">
function fnShowHide( iCol )
{
var oTable = $('#tablename').dataTable();
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
</script>
Later on, I use the following code to hide or show a certain column in the table. 稍后,我使用以下代码隐藏或显示表中的某个列。
<button id="button">
<a href="javascript:void(0);" onclick="fnShowHide(0);">Column1</a>
</button>
<button id="button">
<a href="javascript:void(0);" onclick="fnShowHide(1);">Column2</a>
</button>
<button id="button">
<a href="javascript:void(0);" onclick="fnShowHide(2);">Column3</a>
</button>
How would I make a single button that would hide or show multiple rows rather than just single rows? 如何创建一个隐藏或显示多行而不是单行的按钮?
I am using DataTables to show my data and am using this example for the button above (if that makes a difference). 我正在使用DataTables显示我的数据,并使用此示例作为上面的按钮(如果这有所不同)。
Rather than accepting a single integer as input, why not accept an array of rows you want to hide? 为什么不接受要隐藏的行数组,而不是接受单个整数作为输入?
function fnShowHide( iCols )
{
var i, iCol;
var oTable = $('#tablename').dataTable();
for (i = 0; i < iCols.length; i += 1) {
iCol = iCols[i];
var bVis = oTable.fnSettings().aoColumns[iCol].bVisible;
oTable.fnSetColumnVis( iCol, bVis ? false : true );
}
}
To invoke it for one row you would just use fnShowHide([2])
, and for multiple rows you would pass in multiple values like fnShowHide([2,3,4])
要为一行调用它,您只需使用
fnShowHide([2])
,对于多行,您将传递多个值,如fnShowHide([2,3,4])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.