国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

用JS寫的一個TableView控件代碼

2019-11-21 00:47:35
字體:
來源:轉載
供稿:網友
請看看編碼是否規范,使用是否方便
HTML:
代碼
復制代碼 代碼如下:

<table id="customTableView">
<thead>
<tr>
<td>編號</td>
<td>姓名</td>
</tr>
</thead>
<tbody><!--template-tbody-->
<tr name="" style=" display:none"><!--template-tr-->
<td bind="0"><span class="red">{value}</span></td>
<td bind="1"><strong>{value}</strong></td>
</tr>
</tbody>
</table>
<hr />
<table id="productTableView">
<thead>
<tr>
<td>編號</td>
<td>名稱</td>
</tr>
</thead>
<tbody>
<tr style=" display:none">
<td bind="0"><span class="red">{value}</span></td>
<td bind="1"><strong>{value}</strong></td>
</tr>
</tbody>
</table>

Javascript:
代碼
復制代碼 代碼如下:

<script type="text/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<dataSource.length; 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);
</script>

輸出結果為:
 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 加查县| 运城市| 青田县| 信丰县| 子长县| 皮山县| 周至县| 闽清县| 宁明县| 德钦县| 清河县| 康平县| 论坛| 孟村| 泾阳县| 湖南省| 遂川县| 时尚| 新巴尔虎右旗| 马公市| 门头沟区| 始兴县| 台中市| 闸北区| 黄石市| 南华县| 图木舒克市| 宁都县| 驻马店市| 珠海市| 齐齐哈尔市| 林州市| 连城县| 汤原县| 鹤岗市| 德昌县| 游戏| 湟中县| 平果县| 巴青县| 岚皋县|