欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

layui實(shí)現(xiàn)點(diǎn)擊按鈕給table添加一行

 更新時間:2018年08月10日 08:46:34   作者:sj0613xz  
想實(shí)現(xiàn)點(diǎn)擊按鈕在表格添加一行的功能,但發(fā)現(xiàn)layui并未集成該工具欄,因此,需要自己手動添加這個功能;這篇文章主要介紹了layui點(diǎn)擊按鈕給table添加一行,需要的朋友可以參考下

•問題描述:想實(shí)現(xiàn)點(diǎn)擊按鈕在表格添加一行的功能,但發(fā)現(xiàn)layuii并未集成該工具欄,因此,需要自己手動添加這個功能;

•原先我寫的table是這樣實(shí)現(xiàn)的:

$("#addTable").click(function(){
     var tr=" <tr>"+
       " <td>11</td>"+
       " <td>22</td>"+
       " <td>33</td>"+
       " <td>44</td>"+
       " <td>55</td>"+
       " </tr>";         
   $(".layui-table").append(tr);
  });

并不能實(shí)現(xiàn)添加的效果;后查詢后發(fā)現(xiàn),這樣做是基于table是用靜態(tài)的方式編寫的,即:

<table class="layui-table" lay-data="{height:315, url:'/demo/table/user/', page:true, id:'tableInfo'}" lay-filter="test">
   <thead>
    <tr>
     <th lay-data="{field:'id', width:80, sort: true}">ID</th>
     <th lay-data="{field:'username', width:80}">用戶名</th>
     <th lay-data="{field:'sex', width:80, sort: true}">性別</th>
     <th lay-data="{field:'city'}">城市</th>
     <th lay-data="{field:'sign'}">簽名</th>
     <th lay-data="{field:'experience', sort: true}">積分</th>
     <th lay-data="{field:'score', sort: true}">評分</th>
     <th lay-data="{field:'classify'}">職業(yè)</th>
     <th lay-data="{field:'wealth', sort: true}">財富</th>
    </tr>
   </thead>
  </table>

而我用的是這樣的方式:<table class="layui-hide" id="baseInfo"  lay-filter="demo" lay-data="{height: 'full-200', cellMinWidth: 80, page: true, limit:30}"></table>

關(guān)于列名的定義是寫在table.render({})方法中的

•解決方案:將table改寫成靜態(tài)的方式即可,即第二部分代碼
•此時出現(xiàn)新問題:每點(diǎn)擊一次會出現(xiàn)兩條數(shù)據(jù),應(yīng)做如下修改:$(".layui-table-body .layui-table").append(tr);

最后即可實(shí)現(xiàn)點(diǎn)擊按鈕新增一條數(shù)據(jù)的效果。

總結(jié)

以上所述是小編給大家介紹的layui點(diǎn)擊按鈕給table添加一行,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論