使用jQuery操作HTML的table表格的執行個體解析,jquerytable

來源:互聯網
上載者:User

使用jQuery操作HTML的table表格的執行個體解析,jquerytable

最終:

簡單來看一下其中的主要部分:

HTML:

.td_back_color {   background-color: red; } .td_center {   text-align: center;   font-weight:bold; } 


CSS:

<table id="tbl_count">       <caption>2013春節聚會收支統計</caption>       <tr>         <th>姓名</th>         <th>吃飯</th>         <th>KTV</th>         <th>燒烤</th>         <th>支出</th>         <th>應付</th>       </tr>       <tr>         <th>周競成</th>         <td></td>         <td></td>         <td></td>         <td></td>         <td></td>       </tr>       ......     </table> 
JavaScript:
var data = [ {       picture : "http://ww1.sinaimg.cn/mw690/51baa38egw1dzl6l2hjchj.jpg",       name : "周競成",       leftTime : "二月五號",       phone : "186****2296",       qq : "",       workedIn : "浙江 杭州",       cost : 200,       project : "吃飯,KTV,燒烤"     }, ........ // 初始化shuju     var init = function() {       var tbl_count = $("#tbl_count tr:gt(0)");       // 吃飯       var meal_text = $("#tbl_count tr:first th:eq(1)").text();       // KTV       var ktv_text = $("#tbl_count tr:first th:eq(2)").text();       // 燒烤       var bbq_text = $("#tbl_count tr:first th:eq(3)").text();        $.each(tbl_count, function(i,v){         var tr_info = tbl_count.eq(i);         for (var i = 0; i < data.length; i++) {           var data_info = data[i];           // 判斷姓名相同的           if(data_info.name == tr_info.find("th:first").text()){             if(data_info.project.indexOf(meal_text) != -1){               tr_info.find("td:eq(0)").addClass("td_back_color");             }             if(data_info.project.indexOf(ktv_text) != -1){               tr_info.find("td:eq(1)").addClass("td_back_color");             }             if(data_info.project.indexOf(bbq_text) != -1){               tr_info.find("td:eq(2)").addClass("td_back_color");             }             tr_info.find("td:eq(3)").addClass("td_center").text("¥"+data_info.cost);           }         }       });     }; 

PS:jQuery擷取表格總行數匯總

var rowCount = $('#myTable tr').length; var rowCount = $('#myTable >tbody >tr').length; $("#myTable").attr('rows').length; var rowCount = $('table#myTable:last').index() + 1; //Helper function that gets a count of all the rows <TR> in a table body <TBODY> $.fn.rowCount = function() {   return $('tr', $(this).find('tbody')).length; };  // USAGE:  var rowCount = $('#productTypesTable').rowCount(); alert(jQuery("#jtkList").find("table").eq(0).find("tr").length); 

您可能感興趣的文章:
  • jQuery實現擷取table表格第一列值的方法
  • jQuery外掛程式實現表格隔行變色及滑鼠滑過高亮顯示效果代碼
  • 基於jQuery實現的無重新整理表格分頁執行個體
  • 基於jQuery實現點擊最後一行實現行自增效果的表格
  • jQuery實現的調整表格行tr上下順序
  • jquery調整表格行tr上下順序執行個體講解
  • 基於jquery實現表格無重新整理分頁
  • jquery自訂表格格樣式
  • 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.