javascript 取table中內容__javascript

來源:互聯網
上載者:User
1,有如下表格,我們要取第2行第2列的值 <table id="table1">      <tr>          <td>1行1列</td>          <td>1行2列</td>       </tr>      <tr>          <td>2行1列</td>          <td>2行2列</td>       </tr> </table> 2,取值方法    var value== window.table1.rows.item(0).cells.item(0).innerText; 注意:行號,列號是從 0 開始的   例如 var value = window.table1.rows.item(1).cells.item(1).innerText;   這就取到了第2行第2列的值 3.改進方法    上面的方法,需要知道行號,實踐中是不方便獲得的,下面是改進的方法 <script language="javascript">
 var str;
</script>
  <table >      <tr onMouseDown="str=this.cells.item(0).innerText">          <td>1行1列</td>          <td>1行2列</td>       </tr>      <tr onMouseDown="str=this.cells.item(0).innerText">          <td>2行1列</td>          <td>2行2列</td>       </tr> </table> 當滑鼠按下時,我們就取到了該行第1列的值   <td onMouseDown="str=this.innerText">2行1列</td>   這可以取滑鼠所在列的值  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.