下面小編就為大家?guī)?lái)一篇jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。
html代碼:
<tbody id="history_income_list">
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" onclick="history_income_del(this);" href="###">刪除</a></td>
</tr>
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" href="###">刪除</a></td>
</tr>
<tr>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><input type="text" class="input-s input-w input-hs"></td>
<td align="center"><a class="" href="###">刪除</a></td>
</tr>
</tbody>
方法一:
var trList = $("#history_income_list").children("tr")
for (var i=0;i<trList.length;i++) {
var tdArr = trList.eq(i).find("td");
var history_income_type = tdArr.eq(0).find("input").val();//收入類別
var history_income_money = tdArr.eq(1).find("input").val();//收入金額
var history_income_remark = tdArr.eq(2).find("input").val();// 備注
alert(history_income_type);
alert(history_income_money);
alert(history_income_remark);
}
方法二:
$("#history_income_list").find("tr").each(function(){
var tdArr = $(this).children();
var history_income_type = tdArr.eq(0).find("input").val();//收入類別
var history_income_money = tdArr.eq(1).find("input").val();//收入金額
var history_income_remark = tdArr.eq(2).find("input").val();// 備注
alert(history_income_type);
alert(history_income_money);
alert(history_income_remark);
});
以上這篇jquery遍歷table的tr獲取td的值實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考