如何用javascript实现每隔几秒中把字符串写入表格中
for(var i=0;i <arrResult.length;i++)
{
arrTmp = arrResult[i].split( "!@# "); //分开
num1 = arrTmp; //字段的值
tb1.rows[0].cells[0].innerText=num1; //就写这个单元格
}
清除内容我已经写好,如何 setTimeout 控制i变化,写入不同的字符串(从1到 n)
------解决方案-------------------- <html>
<head>
<title> new document </title>
</head>
<body>
<table border= "1 " id= "tabTarget ">
<tr>
<td> </td>
<td> 1.2 </td>
</tr>
<tr>
<td> 2.1 </td>
<td> 2.2 </td>
</tr>
</table>
<script type= "text/javascript ">
<!--
var i = 0;
// 单位:毫秒
var timeInterval = 1000;
window.setInterval(writeNum, timeInterval);
function writeNum()
{
var oTab = document.getElementById( "tabTarget ");
oTab.rows[0].cells[0].innerHTML = i++;
}
//-->
</script>
</body>
</html>
------解决方案-------------------- "如何用javascript实现每隔几秒中把字符串写入表格中 "
我们来分析下功能
1.隔几秒 setInterval()
2.字符串 input/string s/id/responseText
3.写 function write(xx,xx,xx....)/
4.表格 function(dom)/id.innerHTML
------解决方案--------------------JF
L@_@K
<html>
<head>
<title> new document </title>
</head>
<body>
<table border= "1 " id= "tabTarget ">
<tr>
<td> </td>
<td> 1.2 </td>
</tr>
<tr>
<td> 2.1 </td>
<td> 2.2 </td>
</tr>
</table>
<script type= "text/javascript ">
<!--
var i = 0;
// 单位:毫秒
var timeInterval = 1000;
var arrResult= "11111111@@@2222222222@@@333333333333333@@@444444444444444@@@ <img src=1.JPG /> @@@555555555555555555555 "
var arrTmp = arrResult.split( "@@@ ");
alert(arrTmp);
function writeContent()
{
if (i==arrTmp.length) i=0;
var oTab = document.getElementById( "tabTarget ");
oTab.rows[0].cells[0].innerHTML = arrTmp[i++];
window.setTimeout(writeContent, timeInterval*i);
}
writeContent();
//-->
</script>
</body>
</html>