• [转]jQuery: get table column/row index remove table column (by column number)


    本文转自:http://www.xinotes.org/notes/note/1087/

    <!DOCTYPE html>
    <html>
    <head>
    <title>jQuery Table</title>

    <style type="text/css">
    body {
    font-family: sans-serif;
    }

    table {
    border-collapse: collapse;
    margin-bottom: 5px;
    }

    td {
    padding: 4px;
    border: #4488aa 1px solid;
    }

    input {
    text-align: right;
    padding: 2px;
    width: 20px;
    }
    </style>

    <script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>

    <script type="text/javascript">
    $(function() {
    $('td').click(function() {
    var tr = $(this).parent();
    for (var i = 0; i < tr.children().length; i++) {
    if (tr.children().get(i) == this) {
    var column = i;
    break;
    }
    }

    var tbody = tr.parent();
    for (var j = 0; j < tbody.children().length; j++) {
    if (tbody.children().get(j) == tr.get(0)) {
    var row = j;
    break;
    }
    }
    $('span').text(row + ', ' + column);
    });
    });
    </script>
    </head>

    <body>
    <h1>Table Cell Value</h1>
    <table>
    <tr><td>Cell 1-1</td><td>Cell 1-2</td><td>Cell 1-3</td></tr>
    <tr><td>Cell 2-1</td><td>Cell 2-2</td><td>Cell 2-3</td></tr>
    <tr><td>Cell 3-1</td><td>Cell 3-2</td><td>Cell 3-3</td></tr>
    </table>

    You clicked cell: <span>None</span>
    </body>
    </html>

    本文转自:http://www.jquery4u.com/snippets/jquery-remove-table-column-by-column-number/

    Simple jQuery code snippet to remove an entire table column based on the column number. It also removes the table row heading associated with the removed column.

    //remove the 1st column
    $('#table').find('td,th').first().remove();
    //remove the 1st column
    $('table tr').find('td:eq(1),th:eq(1)').remove();
    //remove the 2nd column
    $('table tr').find('td:eq(1),th:eq(1)').remove();
    //remove the nth column
    $('table tr').find('td:eq(n),th:eq(n)').remove();
  • 相关阅读:
    多态
    封装,继承,多态
    基本类型和引用类型的区别
    第七天 面向对象
    什么是Java线程池
    游戏内核架构
    放松
    静不下来心写代码
    速度和正确率
    理顺思路
  • 原文地址:https://www.cnblogs.com/freeliver54/p/3183297.html
Copyright © 2020-2023  润新知