Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 隐藏基于单词betwen的表列<;th></th>;标签_Jquery - Fatal编程技术网

Jquery 隐藏基于单词betwen的表列<;th></th>;标签

Jquery 隐藏基于单词betwen的表列<;th></th>;标签,jquery,Jquery,我试图使用下面的函数来隐藏一个列,该列基于th标记之间的单词inbetween 下面是我到目前为止所做的,但目前还不起作用 $('#MenuContent_butUsers').click(function () { hidecolumn("Tel"); }); <table id="table" class="table"> <thead> <tr> <th>Name</th&

我试图使用下面的函数来隐藏一个列,该列基于th标记之间的单词inbetween 下面是我到目前为止所做的,但目前还不起作用

$('#MenuContent_butUsers').click(function () {
    hidecolumn("Tel");
});

    <table id="table" class="table">
        <thead>
            <tr>
   <th>Name</th>
   <th>Tel</th>
   <th>Location</th>
</tr>
...


function hidecolumn(columns) {
    var table = $('#table');
    var findColumn = $(table.find('th:contains(' + columns + ')'));
    findColumn.hide();
}
$('MenuContent\u butUsers')。单击(函数(){
hidecolumn(“电话”);
});
名称
电话
位置
...
函数hidecolumn(列){
变量表=$(“#表”);
var findColumn=$(table.find('th:contains('+columns+'));
findColumn.hide();
}
试试这个:

function hidecolumn(columns){
    var table = $('#table');
    var findColumn = $(table.find('th:contains(' + columns + ')'));
    findColumn.hide();
    $('#table tr td:nth-child('+(findColumn.index()+1)+')').hide();
}
见此:

function hidecolumn(columns) {
  var table = $('#table');
  var findColumn = $(table.find('th:contains(' + columns + ')'));
  var index = findColumn.index();
  findColumn.hide();
  $(table.find('tbody td:eq(' + index + ')')).hide();
}
使用此代码

$('#MenuContent_butUsers').click(function () {
    hidecolumn("Tel");
});

    <table id="table" class="table">
        <thead>
            <tr>
   <th>Name</th>
   <th>Tel</th>
   <th>Location</th>
</tr>
...


function hidecolumn(columns) {
    var table = $('#table');
    var findColumn = $('#table th:contains("' + value + '")');
    findColumn.hide();
}
$('MenuContent\u butUsers')。单击(函数(){
hidecolumn(“电话”);
});
名称
电话
位置
...
函数hidecolumn(列){
变量表=$(“#表”);
var findColumn=$(“#表th:contains(“+value+”)”);
findColumn.hide();
}

这很棘手,因为您需要在所有行中隐藏该列的所有单元格。请发布JSFIDLE。这样我们就可以工作了?