html table代码如下:
- <table id="elemet_page_table" class="jsgrid-table">
- <tbody>
- <tr class="jsgrid-header-row">
- <th class="jsgrid-header-cell" style="width: 150px;">名称</th>
- <th class="jsgrid-header-cell" style="width: 50px;">操作</th>
- </tr>
- {% for element_page_name in element_page_list %}
- <tr class="jsgrid-row" id="{{ element_page_name.id }}">
- <td class="jsgrid-cell" style="width: 150px;">
- <input name="name" type="text" value={{ element_page_name.name }} readonly style="border: none;outline:medium;">
- </td>
- <td class="jsgrid-cell jsgrid-control-field jsgrid-align-center" style="width: 50px;">
- <span id="{{ element_page_name.edit_id }}" class="ti-pencil" type="button" title={{ element_page_name.id }} onclick="edit_row(this)">
- </span><span id="{{ element_page_name.save_id }}" class="ti-check" type="button" title={{ element_page_name.id }} onclick="save_row(this)">
- </span><span class="ti-plus" type="button" title={{ element_page_name.id }} onclick="add_row_after(this)">
- </span><span class="ti-trash" type="button" title={{ element_page_name.id }} onclick="delete_row(this)"></span></td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
使用js遍历talbe的所有行和列
- $("#do_save").click(function(){
- // 遍历所有的table-body数据
- $('#elemet_page_table').find('tbody').each(function (i) {
- var row_num=$(this).find('tr').length;
- console.log("总共行数:" + row_num);
- $(this).find('tr').each(function (j) {
- //去除表头
- if(j>0){
- //获取一行有多少列,并去除最后一个操作列
- var cell_num=$(this).find('td').length;
- console.log("单行列数:" + cell_num);
- $(this).find('td').each(function (h) {
- if(h < cell_num-1){
- console.log($(this).context.firstElementChild.value);
- }
- });
- }
- });
- //return false;
- });
- });
11-19 21:56