0

各行にドロップダウン リストを含むテーブルがあります。Rows には id プロパティがありません。したがって、行には id プロパティがないため、ドロップダウン リストで選択した項目と対応する ID 列の値を取得するにはどうすればよいですか。たとえば、最初の行から項目を選択した場合、項目の値と ID 列の値、つまり 204 が必要です。

jQueryで操作するテーブル

これは上記の表のhtmlコードです

 <table class="table-1 gapmb40">
    <thead>
        <tr>
            <th>
                Status
            </th>
            <th>
                <a class="sortable" href="">Featured</a>
            </th>
            <th>
            </th>
            <th>
                <a class="sortable" href="">Date Modified</a>
            </th>
            <th>
            </th>
            <th>
                ID
            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <select class="input-2" name="2">
                    <option value="New">New</option>
                    <option selected="selected" value="Live">Live</option>
                    <option value="AccountOnly">AccountOnly</option>
                    <option value="Hide">Hide</option>
                    <option value="Suspended">Suspended</option>
                </select>
            </td>
            <td>
                <a href="">Feature</a>
            </td>
            <td>
                <a href="">View</a>
            </td>
            <td>
                07/03/2013
            </td>
            <td style="display: none">
                <a href="">LogOnAs</a>
            </td>
            <td>
                204
            </td>
        </tr>
    </tbody>
</table>
4

3 に答える 3

2

すべてのselectboxにクラスを与えてください...たとえばselectClass、jqueryクラスセレクターを使用してください。

これを試して

 $('.selectClass').change(function(e){
     alert($(this).val()); //gives you the selected value
     alert($(this).parents('tr').find('td:eq(5)').text()); //gives you the related TD which is 4th column and gets its text

     //or
     alert($(this).closest('tr').find('td:eq(5)').text()); 
});

ここでフィドル

于 2013-04-22T13:02:09.527 に答える
0

テーブルIDがある場合は、これを試すことができます..

$("#tbltable tr").click(function() {
    var selectedText = $(this).find('select :selected').text();
    var columnID = this.cells[4].innerHTML.toString();
    alert(selectedText + " , " + columnID);
 });
于 2013-04-22T13:13:23.313 に答える