简体   繁体   中英

How can I query select all inputs from table column

I am trying to get the input from a table form. The table has but 2 columns how can I get the input from these? I want to have a different var for each column of items? Should I use an array? This is my table:

       <table id="resultTable" cellpadding="1" cellspacing="1" border="1">
            <tr>
                <th scope="col"></th>
                <th scope="col">Hoeveelheid</th>
                <th scope="col">Gewicht x KG</th>
            </tr>
            <tr>
                <td>1</td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
            </tr>
            <tr>
                <td>2</td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
            </tr>
            <tr>
                <td>3</td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
                <td><INPUT TYPE="NUMBER" MIN="0" MAX="10" STEP="1" ></td>
            </tr>
        </table>

What is the best way to get around this? I tried to select by tag name.

Here a quick one for jQuery:

Replace tableid with the id of your table

var col1_Array = $('#tableid td:nth-child(1)').map(function(){
   return $(this).text();
}).get()​;

var col2_Array = $('#tableid td:nth-child(2)').map(function(){
   return $(this).text();
}).get()​;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM