[转]jquery遍历table的tr获取td的值 - CQ_LQJ

WBOY
풀어 주다: 2016-05-20 13:48:49
원래의
1338명이 탐색했습니다.

html代码:

<span style="color: #008080;"> 1 <span style="color: #0000ff;">tbody <span style="color: #ff0000;">id<span style="color: #0000ff;">="history_income_list"<span style="color: #0000ff;">>
<span style="color: #008080;"> 2 <span style="color: #0000ff;">tr<span style="color: #0000ff;">>
<span style="color: #008080;"> 3 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;"> 4 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;"> 5 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;"> 6 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>a <span style="color: #ff0000;">class<span style="color: #0000ff;">=""<span style="color: #ff0000;"> onclick<span style="color: #0000ff;">="history_income_del(this);"<span style="color: #ff0000;"> href<span style="color: #0000ff;">="###"<span style="color: #0000ff;">>删除<span style="color: #0000ff;"><span style="color: #800000;">a<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;"> 7 <span style="color: #0000ff;"><span style="color: #800000;">tr<span style="color: #0000ff;">>
<span style="color: #008080;"> 8 <span style="color: #0000ff;">tr<span style="color: #0000ff;">>
<span style="color: #008080;"> 9 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">10 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">11 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">12 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>a <span style="color: #ff0000;">class<span style="color: #0000ff;">=""<span style="color: #ff0000;"> href<span style="color: #0000ff;">="###"<span style="color: #0000ff;">>删除<span style="color: #0000ff;"><span style="color: #800000;">a<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">13 <span style="color: #0000ff;"><span style="color: #800000;">tr<span style="color: #0000ff;">>
<span style="color: #008080;">14 <span style="color: #0000ff;">tr<span style="color: #0000ff;">>
<span style="color: #008080;">15 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">16 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">17 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>input <span style="color: #ff0000;">type<span style="color: #0000ff;">="text"<span style="color: #ff0000;"> class<span style="color: #0000ff;">="input-s input-w input-hs"<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">18 <span style="color: #0000ff;">td <span style="color: #ff0000;">align<span style="color: #0000ff;">="center"<span style="color: #0000ff;">>a <span style="color: #ff0000;">class<span style="color: #0000ff;">=""<span style="color: #ff0000;"> href<span style="color: #0000ff;">="###"<span style="color: #0000ff;">>删除<span style="color: #0000ff;"><span style="color: #800000;">a<span style="color: #0000ff;">><span style="color: #800000;">td<span style="color: #0000ff;">>
<span style="color: #008080;">19 <span style="color: #0000ff;"><span style="color: #800000;">tr<span style="color: #0000ff;">>
<span style="color: #008080;">20 <span style="color: #0000ff;"><span style="color: #800000;">tbody<span style="color: #0000ff;">>
<span style="color: #008080;">21   </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
로그인 후 복사

 

 

方法一:

<span style="color: #0000ff;">var trList = $("#history_income_list").children("tr"<span style="color: #000000;">)
    <span style="color: #0000ff;">for (<span style="color: #0000ff;">var i=0;i<trlist.length style="color: #000000;">) {
        <span style="color: #0000ff;">var tdArr = trList.eq(i).find("td"<span style="color: #000000;">);
        <span style="color: #0000ff;">var history_income_type = tdArr.eq(0).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">收入类别
        <span style="color: #0000ff;">var history_income_money = tdArr.eq(1).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">收入金额
        <span style="color: #0000ff;">var history_income_remark = tdArr.eq(2).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">    备注
<span style="color: #000000;">        
        alert(history_income_type);
        alert(history_income_money);
        alert(history_income_remark);
    }</span></span></span></span></span></span></span></span></span></span></span></span></trlist.length></span></span></span></span>
로그인 후 복사

方法二:

$("#history_income_list").find("tr").each(<span style="color: #0000ff;">function<span style="color: #000000;">(){
        <span style="color: #0000ff;">var tdArr = $(<span style="color: #0000ff;">this<span style="color: #000000;">).children();
        <span style="color: #0000ff;">var history_income_type = tdArr.eq(0).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">收入类别
        <span style="color: #0000ff;">var history_income_money = tdArr.eq(1).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">收入金额
        <span style="color: #0000ff;">var history_income_remark = tdArr.eq(2).find("input").val();<span style="color: #008000;">//<span style="color: #008000;">    备注
<span style="color: #000000;">        
        alert(history_income_type);
        alert(history_income_money);
        alert(history_income_remark);
        
        
    });</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
로그인 후 복사
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!