jquery to loop through table rows and cells, where checkob is checked, concatenate

后端 未结 2 777
旧巷少年郎
旧巷少年郎 2020-12-24 02:57

I have a table with multiple rows. there are several columns in the table with checkboxes. I need to loop through each of the checkboxes, where it is checked concatenate/joi

相关标签:
2条回答
  • 2020-12-24 03:24

    UPDATED

    I've updated your demo: http://jsfiddle.net/terryyounghk/QS56z/18/

    Also, I've changed two ^= to *=. See http://api.jquery.com/category/selectors/

    And note the :checked selector. See http://api.jquery.com/checked-selector/

    function createcodes() {
    
        //run through each row
        $('.authors-list tr').each(function (i, row) {
    
            // reference all the stuff you need first
            var $row = $(row),
                $family = $row.find('input[name*="family"]'),
                $grade = $row.find('input[name*="grade"]'),
                $checkedBoxes = $row.find('input:checked');
    
            $checkedBoxes.each(function (i, checkbox) {
                // assuming you layout the elements this way, 
                // we'll take advantage of .next()
                var $checkbox = $(checkbox),
                    $line = $checkbox.next(),
                    $size = $line.next();
    
                $line.val(
                    $family.val() + ' ' + $size.val() + ', ' + $grade.val()
                );
    
            });
    
        });
    }
    
    0 讨论(0)
  • 2020-12-24 03:25

    Try this:

    function createcodes() {
    
        $('.authors-list tr').each(function () {
            //processing this row
            //how to process each cell(table td) where there is checkbox
            $(this).find('td input:checked').each(function () {
    
                 // it is checked, your code here...
            });
        });
    }
    
    0 讨论(0)
提交回复
热议问题