javascript
html页面tableview,用JS写的一个TableView控件代码
請看看編碼是否規范,使用是否方便
HTML:
代碼
編號姓名
{value}{value}編號名稱
{value}{value}Javascript:
代碼
//class TableView {
//構造函數
function TableView(ID){
var htmlTable = document.getElementById(ID);
this.container = htmlTable.getElementsByTagName("tbody")[0];
this.template = this.container.getElementsByTagName("tr")[0];
}
//成員方法
TableView.prototype.bind = function(dataSource) {
var template = this.template;
var container = this.container;
for(var k=0; k
var newRow = template.cloneNode(true);
newRow.removeAttribute("id");
newRow.removeAttribute("style");
for(var i=0;i<2;i++) {
var dataItem = newRow.cells[i];
dataItem.innerHTML = dataItem.innerHTML.replace("{value}", dataSource[k][dataItem.getAttribute("bind")]);
}
container.appendChild(newRow);
}
}
//}
//測試-1
var productDataSource = [["001","產品名稱1"],["002","產品名稱2"]];
var productTableView = new TableView("productTableView");
productTableView.bind(productDataSource);
//測試-2
var customDataSource = [["001","客戶姓名1"],["002","客戶姓名2"]];
var customTableView = new TableView("customTableView");
customTableView.bind(customDataSource);
輸出結果為:
總結
以上是生活随笔為你收集整理的html页面tableview,用JS写的一个TableView控件代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2019运管取消了滴滴还查吗_劳务资质2
- 下一篇: 聚类中心坐标公式如何使用_如何使用CAD