jQuery擷取Table某列的值

來源:互聯網
上載者:User

標籤:http   rac   9.png   post   style   close   url   add   eve   

在寫此篇博文時,發現在以前曾寫過《擷取DataTable選擇第一行某一列值》http://www.cnblogs.com/insus/p/5434062.html 。

但是與此篇所說的完全不一樣。這篇Insus.NET需要的是jQuery去擷取html table的某一行某一列的資料。

如下表:

Html code:

<table>        <tr>            <th style="width:10px;"><input id="SelectAll" type="checkbox" /></th>            <th>ID</th>            <th>費用名目</th>            <th>費用解釋</th>            <th>收費明細</th>            <th>幣種</th>            <th style="width:50px;">操作</th>        </tr>        @foreach (var m in new HighwayAdditionalChargeEntity().HighwayAdditionalCharges())            {            <tr class="trData">                <td><input id="" class="SelectSingle" type="checkbox" value="@m.HighwayAdditionalCharge_nbr" /></td>                <td>@m.HighwayAdditionalCharge_nbr</td>                <td>@m.Item</td>                <td>@m.Description</td>                <td>@m.Itemizations</td>                <td>@m.Currency</td>                <td>                    <input class="Select" id="ButtonSelect" type="button" value="選擇" />                </td>            </tr>        }    </table>
Source Code

 

 當使用者點擊某一行最後一列的“選擇”銨鈕時,想擷取此銨鈕本行中某一列的資料。
Insus.NET有在圖中示出,列與索引。索引是從0開始。如想擷取“費用名目”列值,此列的列索引是2。



 示範:

 

上面我們擷取值,是使用了.text()方法。但某一時候,你想擷取列的值,它是html代碼,那我們可以使用.html()方法。下面Insus.NET稍修改一下:


 

示範:

 
其實,使用索引來擷取值,只是一種方法,但它不是Insus.NET最理想的方法首選。由於資料行是動態呈現,列也有可能會變更。因此Insus.NET還是習慣使用樣式class來實現:
舉個列子,想擷取“費用解釋”列的值,在此列添加一個class:


 

jQuery代碼:

 

示範:

 

jQuery擷取Table某列的值

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.