bootstrap table單元格新增行并編輯
table單元格新增行并編輯,具體內(nèi)容如下
需要
bootstrap.min.css —— [ Bootstrap ]
jquery-1.8.2.min.js —— [ Jquery ]
代碼
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>新建HTML</title> <script type="text/javascript" src="jquery-1.8.2.min.js"></script> <script type="text/javascript"> function save_para_table(){ var tableinfo = gettableinfo(); alert(tableinfo); } //get table infomation function gettableinfo(){ var key = ""; var value = ""; var tabledata = ""; var table = $("#para_table"); var tbody = table.children(); var trs = tbody.children(); for(var i=1;i<trs.length;i++){ var tds = trs.eq(i).children(); for(var j=0;j<tds.length;j++){ if(j==0){ if(tds.eq(j).text()==null||tds.eq(j).text()==""){ return null; } key = "key\":\""+tds.eq(j).text(); } if(j==1){ if(tds.eq(j).text()==null||tds.eq(j).text()==""){ return null; } value = "value\":\""+tds.eq(j).text(); } } if(i==trs.length-1){ tabledata += "{\""+key+"\",\""+value+"\"}"; }else{ tabledata += "{\""+key+"\",\""+value+"\"},"; } } tabledata = "["+tabledata+"]"; return tabledata; } function tdclick(tdobject){ var td=$(tdobject); td.attr("onclick", ""); //1,取出當(dāng)前td中的文本內(nèi)容保存起來(lái) var text=td.text(); //2,清空td里面的內(nèi)容 td.html(""); //也可以用td.empty(); //3,建立一個(gè)文本框,也就是input的元素節(jié)點(diǎn) var input=$("<input>"); //4,設(shè)置文本框的值是保存起來(lái)的文本內(nèi)容 input.attr("value",text); input.bind("blur",function(){ var inputnode=$(this); var inputtext=inputnode.val(); var tdNode=inputnode.parent(); tdNode.html(inputtext); tdNode.click(tdclick); td.attr("onclick", "tdclick(this)"); }); input.keyup(function(event){ var myEvent =event||window.event; var kcode=myEvent.keyCode; if(kcode==13){ var inputnode=$(this); var inputtext=inputnode.val(); var tdNode=inputnode.parent(); tdNode.html(inputtext); tdNode.click(tdclick); } }); //5,將文本框加入到td中 td.append(input); var t =input.val(); input.val("").focus().val(t); // input.focus(); //6,清除點(diǎn)擊事件 td.unbind("click"); } var row=0; function addtr(){ if(row<8){ row++; var table = $("#para_table"); var tr= $("<tr>" + "<td style='text-align: center;' onclick='tdclick(this)'>"+"</td>" + "<td style='text-align: center;' onclick='tdclick(this)'>"+"</td>" + "<td align='center' onclick='deletetr(this)'><button type='button' class='btn btn-xs btn-link' >"+"刪除"+"</button></td></tr>"); table.append(tr); }else{ alert("已達(dá)到發(fā)票能開(kāi)具的最大商品明細(xì)行數(shù)"); } } function deletetr(tdobject){ row--; var td=$(tdobject); td.parents("tr").remove(); } </script> <link href="bootstrap.min.css" rel="external nofollow" rel="stylesheet" type="text/css"> </head> <body> <table class="table table-bordered" id="para_table"> <thead> <tr> <th style="text-align:center" width="200">名稱(chēng)</th> <th style="text-align:center" width="200">值</th> <th style="text-align:center" width="100">操作</th> </tr> </thead> <tbody> <tr> <td style="text-align:center; " onclick="tdclick(this)"></td> <td style="text-align:center; " onclick="tdclick(this)"></td> <td style="text-align:center; " onclick="deletetr(this)"><button type="button" class="btn btn-xs btn-link">刪除</button></td> </tr> </tbody> </table> <div id="addtrdiv" style="margin-top:-15px; width: 15%; float: right;"> <button type="button" class="btn btn-xs btn-link" onclick="addtr()">添加</button> </div> </body> </html>
效果圖:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Bootstrap Table 在指定列中添加下拉框控件并獲取所選值
- Bootstrap Table列寬拖動(dòng)的方法
- bootstrap table列和表頭對(duì)不齊的解決方法
- Bootstrap Table使用方法詳解
- JS組件Bootstrap Table使用方法詳解
- bootstrap table實(shí)現(xiàn)單擊單元格可編輯功能
- 值得分享的bootstrap table實(shí)例
- 值得分享的輕量級(jí)Bootstrap Table表格插件
- 基于BootStrap的Metronic框架實(shí)現(xiàn)頁(yè)面鏈接收藏夾功能按鈕移動(dòng)收藏記錄(使用Sortable進(jìn)行拖動(dòng)排序)
- Bootstrap?table列上下移動(dòng)效果
相關(guān)文章
有趣的JavaScript隱式類(lèi)型轉(zhuǎn)換操作實(shí)例分析
這篇文章主要介紹了JavaScript隱式類(lèi)型轉(zhuǎn)換操作,結(jié)合實(shí)例形式分析了JavaScript隱式類(lèi)型轉(zhuǎn)換操作相關(guān)實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下2020-05-05Bootstrap導(dǎo)航中表單簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Bootstrap導(dǎo)航中表單簡(jiǎn)單實(shí)現(xiàn)代碼,含路徑導(dǎo)航的具體實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03JS實(shí)現(xiàn)將數(shù)字金額轉(zhuǎn)換為大寫(xiě)人民幣漢字的方法
這篇文章主要介紹了JS實(shí)現(xiàn)將數(shù)字金額轉(zhuǎn)換為大寫(xiě)人民幣漢字的方法,涉及javascript字符串與數(shù)組操作的相關(guān)技巧,需要的朋友可以參考下2016-08-08基于p5.js 2D圖像接口的擴(kuò)展(交互實(shí)現(xiàn))
這篇文章主要為大家詳細(xì)介紹了基于p5.js 2D圖像接口的擴(kuò)展,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11JS計(jì)算距當(dāng)前時(shí)間的時(shí)間差實(shí)例
下面小編就為大家分享一篇JS計(jì)算距當(dāng)前時(shí)間的時(shí)間差實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12TypeScript實(shí)現(xiàn)數(shù)組和樹(shù)的相互轉(zhuǎn)換
樹(shù)或者圖是個(gè)比較抽象的概念,并不存在這樣的數(shù)據(jù)類(lèi)型。數(shù)組就比較簡(jiǎn)單了,因此數(shù)組和樹(shù)的轉(zhuǎn)換可以理解為數(shù)組和對(duì)象之間的轉(zhuǎn)換。本文將用TypeScript實(shí)現(xiàn)數(shù)組和樹(shù)的相互轉(zhuǎn)換,感興趣的可以了解一下2022-06-06javascript使用百度地圖api和html5特性獲取瀏覽器位置
本文介紹了javascript使用百度地圖api和html5特性獲取瀏覽器位置的小功能,大家參考使用吧2014-01-01