当前位置:K88软件开发文章中心编程语言JavaScriptJS01 → 文章内容

javascript动态改变表格单元格中的内容

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:57:03

<
TABLE 
id="
table1"
 
border=1 
width="
150"
>

<
TR>

<
TD 
align="
center"
 
width="
50%"
>
0,0<
/TD>

<
TD 
align="
center"
>
0,1<
/TD>

<
/TR>

<
TR>

<
TD 
align="
center"
>
1,0<
/TD>

<
TD 
align="
center"
>
1,1<
/TD>

<
/TR>

<
/TABLE>

<
form 
name="
form1"
 
method="
post"
 
action="
"
>

输入要添加的文字:<
br>
<
input 
type="
text"
 
name="
f1"
>
<
br>

行<
input 
type="
text"
 
size="
5"
 
name="
row"
 
value="
0"
>
&

#38
nbsp

列<
input 
type="
text"
 
size="
5"
 
name="
col"
 
value="
0"
>
<
br>

<
input 
type="
button"
 
value="
添加"
 
onclick="
f2()"
>

<
/form>

<
script>
 
 

function 
f2()

{
col=parseInt(document.form1.col.value)
 
 

row=parseInt(document.form1.row.value)

f1=document.form1.f1.value

document.getElementById("
table1"
).rows.item(row).cells.item(col).innerHTML=f1

}
<
/script>


javascript动态改变表格单元格中的内容