81,092
社区成员
发帖
与我相关
我的任务
分享
<html>
<Table id='myTable' border='1'>
</Table>
<br>
row:<input type='text' id='rowIndex'>
col:<input type='text' id='colIndex'>
<input type='button' value='create cell' onclick='createCell()'>
<input type='button' value='get cell value' onclick='getCellValue()'>
<input type='text' id='cellValue'>
<input type='button' value='set cell value' onclick='setCellValue()'>
<script language='javascript'>
function createCell() {
var rowIdx = rowIndex.value-0;
var colIdx = colIndex.value-0;
if ((rowIdx<0) || (colIdx<0)) {
alert('invalid cell index');
return;
}
var tbl = myTable;
while (tbl.rows.length<rowIdx+1) {
tbl.insertRow();
}
var row = tbl.rows[rowIdx];
var cell;
while (row.cells.length<colIdx+1) {
cell = row.insertCell();
cell.innerText=' ';
}
}
function getCellValue() {
var rowIdx = rowIndex.value-0;
var colIdx = colIndex.value-0;
if ((rowIdx<0) || (colIdx<0)) {
alert('invalid cell index');
return;
}
var tbl = myTable;
if (tbl.rows.length<rowIdx+1){
alert('cell not exists');
return;
}
var row = tbl.rows[rowIdx];
if (row.cells.length<colIdx+1) {
alert('cell not exists');
return;
}
var cell = row.cells[colIdx];
alert(cell.innerText);
}
function setCellValue() {
var rowIdx = rowIndex.value-0;
var colIdx = colIndex.value-0;
var v=cellValue.value;
if ((rowIdx<0) || (colIdx<0)) {
alert('invalid cell index');
return;
}
createCell();
var tbl = myTable;
var row= tbl.rows[rowIdx];
var cell = row.cells[colIdx];
cell.innerText = v;
}
</script>
</html>
<!-- 我这里只有一个datalistTable,你可以改成:datalistTable1为第一个table,datalistTable2为第2个table -->
<table class="datalistTable" align="center" style="width:950px;"></table>
/** result是后台传过来的一个JS对象,result.dataList封装了个数组,你可以改成dataList1为第一个表格的数据,dataList2为第2个表格的数据 */
function reflashTable(result){
// 用JS来拼html语言,拼出一个Table
var strTb="";
strTb+='<caption>列表信息</caption>';
strTb+='<tr onclick="trClick(this)">';
strTb+= '<th>ID</th>';
strTb+= '<th style="width:150px;">昵称</th>';
//strTb+= '<th style="width:50px;">姓名</th>';
strTb+= '<th style="width:100px;">XXXX</th>';
strTb+= '<th style="width:80px;">X币</th>';
strTb+= '<th style="width:100px;">IP</th>';
strTb+= '<th width="120px" >XX时间<span class="headHand" id="head_registetime">↑</span></th>';
strTb+= '<th width="120px" >最近XX<span class="headHand" id="head_registetime">↑</span></th>';
strTb+= '<th width="120px" >最近ZZ<span class="headHand" id="head_registetime">↑</span></th>';
strTb+= '<th width="35px" >操作</th>';
strTb+='</tr>';
var dataList = result.dataList;
for (var i=0; i<dataList.length; i++) {
var data = dataList[i];
strTb+='<tr>';
strTb+='<td class="number">'+data.playerid+'</td>';
strTb+='<td>'+getHtmlStr(data.nickname)+'</td>';
//strTb+='<td>'+data.realname+'</td>';
strTb+='<td class="number chips" title="XX">'+data.xx+'</td>';
strTb+='<td class="number chips" title="X币">'+data.xxb+'</td>';
strTb+='<td style="width:95;">'+data.ip+'</td>';
strTb+='<td title="XX时间(北京时间)">'+data.xxTimeDesc+'</td>';
strTb+='<td title="XX时间(北京时间)">'+data.lastxxtimeDesc+'</td>';
strTb+='<td title="最后XX时间(北京时间)" name="'+data.zztime+'">'+data.zzDesc+'</td>';
strTb+='<td style="text-align:center;">';
strTb+= '<a href="javascript:void(0)" onclick="playerDtl(\''+data.playerid+'\', \''+getJsStr(data.nickname)+'\', this, event)" >详情</a></td>';
strTb+='</tr>';
}
// 这里用到了JQuery语言的查找元素,再把table写到页面
$(".datalistTable").html(strTb);
}