至少有两个错误:
1. 文本框没有 onkeyup 事件
2. 文本框的 name 与你自定义的函数同名, 系统无法正确得知你调用的是控件还是函数<script language="JavaScript">
function total2(form)
{
setTimeout("document.all.price.innerText = document."+ form.name +".total.value");
}
</script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="44%">
<input type="text" name="total" onkeydown="total2(this.form)">
</td>
<td width="56%">
<div id="price"> </div>
</td>
</tr>
</table>
</form>
1. 文本框没有 onkeyup 事件
2. 文本框的 name 与你自定义的函数同名, 系统无法正确得知你调用的是控件还是函数<script language="JavaScript">
function total2(form)
{
setTimeout("document.all.price.innerText = document."+ form.name +".total.value");
}
</script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="44%">
<input type="text" name="total" onkeydown="total2(this.form)">
</td>
<td width="56%">
<div id="price"> </div>
</td>
</tr>
</table>
</form>
<script language="JavaScript">
function total(form,i){
total="total"+i
price ="price"+i
document.all.price.innerText=form.total.value
}
</script><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="44%">
<input type="text" name="total1" onkeyup="total(this.form,1)">
</td>
<td width="56%">
<div id="price1"> </div>
</td>
</tr> <td width="44%">
<input type="text" name="total2" onkeyup="total(this.form,2)">
</td>
<td width="56%">
<div id="price2"> </div>
</td>
</tr> </table>
</form>
<script language="JavaScript">
function total(form,i){
total="total"+i
price ="price"+i
document.all.price.innerText=form.total.value
}
</script><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="44%">
<input type="text" name="total1" onkeyup="total(this.form,1)">
</td>
<td width="56%">
<div id="price1"> </div>
</td>
</tr> <td width="44%">
<input type="text" name="total2" onkeyup="total(this.form,2)">
</td>
<td width="56%">
<div id="price2"> </div>
</td>
</tr> </table>
</form>
所以说楼主, 你不能用 onkeyup 这个事件了
function total(form,i)
{
setTimeout("document.all.price"+i+".innerText = document."+ form.name +".total"+i+".value");
}
</script><body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="44%">
<input type="text" name="total1" onkeydown="total(this.form,1)">
</td>
<td width="56%">
<div id="price1"> </div>
</td>
</tr> <td width="44%">
<input type="text" name="total2" onkeydown="total(this.form,2)">
</td>
<td width="56%">
<div id="price2"> </div>
</td>
</tr> </table>
</form>