복붙노트

[JQUERY] jQuery를 : 테이블의 행의 수를 계산

JQUERY

jQuery를 : 테이블의 행의 수를 계산

해결법


  1. 1.모든 행을 선택하고 길이를 취할 것 선택기를 사용합니다.

    모든 행을 선택하고 길이를 취할 것 선택기를 사용합니다.

    var rowCount = $('#myTable tr').length;
    

    참고 :이 방법은 또한 모든 중첩 된 테이블의 모든 TRS를 계산!


  2. 2.당신이 사용하는 경우 또는 테이블에 다음과 같은 구문을 사용해야합니다 또는 당신이 잘못된 값을 얻을 것이다 :

    당신이 사용하는 경우 또는 테이블에 다음과 같은 구문을 사용해야합니다 또는 당신이 잘못된 값을 얻을 것이다 :

    var rowCount = $('#myTable >tbody >tr').length;
    

  3. 3.또한 ...

    또한 ...

    var rowCount = $('table#myTable tr:last').index() + 1;
    

    js 휘티 d 혀라도

    이 중첩 된 테이블 행이 또한 계산되지 않도록합니다.


  4. 4.글쎄, 난 테이블의 ATTR 행을받을 수 있도록 컬렉션의 길이를 얻을 :

    글쎄, 난 테이블의 ATTR 행을받을 수 있도록 컬렉션의 길이를 얻을 :

    $("#myTable").attr('rows').length;
    

    내가 jQuery를 덜 작동하는지 생각합니다.


  5. 5.여기에 필자는 다음과 같습니다

    여기에 필자는 다음과 같습니다

    //Helper function that gets a count of all the rows <TR> in a table body <TBODY>
    $.fn.rowCount = function() {
        return $('tr', $(this).find('tbody')).length;
    };
    

    용법:

    var rowCount = $('#productTypesTable').rowCount();
    

  6. 6.나는 다음을 가지고 :

    나는 다음을 가지고 :

    jQuery('#tableId').find('tr').index();
    

  7. 7.헤더 없음

    헤더 없음

    $("#myTable > tbody").children.length
    

    헤더는 존재하는 경우

    $("#myTable > tbody").children.length -1
    

    즐겨!!!


  8. 8.나는이 작품을 쓴, 그래서 나는, AJAX를 반환에서이 작업을 수행 할 수있는 방법이 필요했습니다 :

    나는이 작품을 쓴, 그래서 나는, AJAX를 반환에서이 작업을 수행 할 수있는 방법이 필요했습니다 :

    <p id="num_results">Number of results: <span></span></p>
    
    <div id="results"></div>
    
    <script type="text/javascript">
    $(function(){
        ajax();
    })
    
    //Function that makes Ajax call out to receive search results
    var ajax = function() {
        //Setup Ajax
        $.ajax({
            url: '/path/to/url', //URL to load
            type: 'GET', //Type of Ajax call
            dataType: 'html', //Type of data to be expected on return
            success: function(data) { //Function that manipulates the returned AJAX'ed data
                $('#results').html(data); //Load the data into a HTML holder
                var $el = $('#results'); //jQuery Object that is holding the results
                setTimeout(function(){ //Custom callback function to count the number of results
                    callBack($el);
                });
            }
        });
    }
    
    //Custom Callback function to return the number of results
    var callBack = function(el) {
        var length = $('tr', $(el)).not('tr:first').length; //Count all TR DOM elements, except the first row (which contains the header information)
        $('#num_results span').text(length); //Write the counted results to the DOM
    }
    </script>
    

    분명히 이것은 간단한 예이지만, 도움이 될 수 있습니다.


  9. 9.나는 당신이 일 및 테이블의 내부 테이블에서 모든 행을 계산하지 않고 행을 계산하려면이 정말 잘 작동하는 것으로 확인 :

    나는 당신이 일 및 테이블의 내부 테이블에서 모든 행을 계산하지 않고 행을 계산하려면이 정말 잘 작동하는 것으로 확인 :

    var rowCount = $("#tableData > tbody").children().length;
    

  10. 10.

    row_count =  $('#my_table').find('tr').length;
    column_count =  $('#my_table').find('td').length / row_count;
    

  11. 11.VAR. trLength = jQuery를 ( '# tablebodyID> TR') 길이;

    VAR. trLength = jQuery를 ( '# tablebodyID> TR') 길이;

  12. from https://stackoverflow.com/questions/1149958/jquery-count-number-of-rows-in-a-table by cc-by-sa and MIT license