How to iterate through a table rows and get the cell values using jQuery

前端 未结 5 1386
天涯浪人
天涯浪人 2020-12-30 04:16

I am creating the below table dynamically using jQuery... After executing my code I get the table as below:

5条回答
  •  别那么骄傲
    2020-12-30 05:06

    You got your answer, but why iterate over the tr when you can go straight for the inputs? That way you can store them easier into an array and it reduce the number of CSS queries. Depends what you want to do of course, but for collecting data it is a more flexible approach.

    http://jsfiddle.net/zqpgq/

    var array = [];
    
    $("tr.item input").each(function() {
        array.push({
            name: $(this).attr('class'),
            value: $(this).val()
        });
    });
    
    console.log(array);​
    

提交回复
热议问题