最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

用JS寫的一個TableView控件代碼

 更新時間:2010年01月23日 23:29:08   作者:  
JS寫的一個TableView控件代碼,方便輸出表格。
請看看編碼是否規(guī)范,使用是否方便
HTML:
代碼
復(fù)制代碼 代碼如下:

<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:
代碼
復(fù)制代碼 代碼如下:

<script type="text/javascript">
//class TableView {
//構(gòu)造函數(shù)
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","產(chǎn)品名稱1"],["002","產(chǎn)品名稱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>

輸出結(jié)果為:
 

相關(guān)文章

最新評論

登封市| 阜城县| 化州市| 厦门市| 建宁县| 绵阳市| 大城县| 壤塘县| 敦煌市| 姚安县| 尚义县| 望奎县| 盐城市| 通榆县| 舒兰市| 五寨县| 泗阳县| 安乡县| 樟树市| 江山市| 保德县| 察雅县| 宜昌市| 大洼县| 进贤县| 昌吉市| 湘潭县| 乐陵市| 赣州市| 资阳市| 科技| 清远市| 井冈山市| 曲周县| 建始县| 西昌市| 乐亭县| 永清县| 贺兰县| 巨鹿县| 赞皇县|