Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.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/4/algorithm/11.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
Javascript 如何从表中删除列_Javascript_Jquery_Jquery Ui - Fatal编程技术网

Javascript 如何从表中删除列

Javascript 如何从表中删除列,javascript,jquery,jquery-ui,Javascript,Jquery,Jquery Ui,如何从表中删除列。用于删除列号的文本框值。 有关更多信息,请参阅此链接: Javascript: $("#target").click(function () { var removecolunms = $("#textval").val(); $('table colgroup').find('col:eq("' + removecolunms + '")').remove(); $('table tr').find('th:eq("' + removecolunms

如何从表中删除列。用于删除列号的文本框值。 有关更多信息,请参阅此链接: Javascript:

$("#target").click(function () {
    var removecolunms = $("#textval").val();
    $('table colgroup').find('col:eq("' + removecolunms + '")').remove();
    $('table tr').find('th:eq("' + removecolunms + '")').remove();
    $('table tr').find('td:eq("' + removecolunms + '")').remove();
});


如果
0
是columnindex

,则必须遍历表中的每一行,并删除相应的td和th元素

$('tr').each(function(){
    $(this).find('td:nth-child(' + colIndex + ')').remove();
    $(this).find('th:nth-child(' + colIndex + ')').remove();
});
退房


fiddle

你想要实现什么?您能详细说明一下吗?您的文本中显示了“要删除多少列”,但您使用了:eq()选择器,这实际上是一个迭代,而不是一个数量。只是旁注
$('tr').each(function(){
    $(this).find('td:nth-child(' + colIndex + ')').remove();
    $(this).find('th:nth-child(' + colIndex + ')').remove();
});
  <table border="1" style="width:100%" class="dataupdate">
    <tr>
        <td>Row 1 Col1</td>
        <td>Row 1 Col2</td>
        <td>Row 1 Col3</td>
        <td>Row 1 Col4</td>
        <td>Row 1 Col5</td>
        <td>Row 1 Col6</td>
    </tr>
    <tr>
        <td>Row 2 Col1</td>
        <td>Row 2 Col2</td>
        <td>Row 2 Col3</td>
        <td>Row 2 Col4</td>
        <td>Row 2 Col5</td>
        <td>Row 2 Col6</td>
    </tr>
    <tr>
        <td>Row 3 Col1</td>
        <td>Row 3 Col2</td>
        <td>Row 3 Col3</td>
        <td>Row 3 Col4</td>
        <td>Row 3 Col5</td>
        <td>Row 3 Col6</td>
    </tr>   
    </table> 
    <form>
          <input type="text" id="numrow" placeholder="Row" >
          <input type="text" id="numcol" placeholder="Column">
          <input  type="button" id="removeButton" value="Remove" >  
    </form>
  $('#removeButton').click(
  function(){
   var numrow = $('#numrow').val();
   var numcol = $('#numcol').val();  
$('.dataupdate tr:nth-child('+numrow+') td:nth-child('+numcol+')').remove()
  });