文本框计算

San0011 2005-07-06 04:52:19
有一系列的INPUT文本框,
name=txtFirst1(txtFirst2,txtFirst3,……)
name=txtSecond1(txtFirst2,txtFirst3,……)
name=txtThird1(txtThird2,txtThird3,……)

是否可以用ducument.all["text"+i].value来使用里面的值来进行计算呢?

function cal()
{
total = ducument.all["txtFirst"+i].value + ducument.all["txtSecond"+i].value;
ducument.all["txtThird"+i].value = total;
}

或者有其它的方法,请大家多多指教。
...全文
177 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
San0011 2005-07-07
  • 打赏
  • 举报
回复
大小写没有问题的。另外,页面刷新是怎么回事的?
谢谢!
underone 2005-07-07
  • 打赏
  • 举报
回复
注意文本框的name大小写
San0011 2005-07-07
  • 打赏
  • 举报
回复
我按了提交后那些文本框里没有写上值、整个页面却都刷新了一遍,那是怎么回事的呢?
yeyu710 2005-07-06
  • 打赏
  • 举报
回复
楼主的方法是行得通的,我今天刚好就用到了啊
zhiin1 2005-07-06
  • 打赏
  • 举报
回复
<input name="txtFirst1" value="1">
<input name="txtFirst2" value="2">
<input name="txtFirst3" value="3">
<br>

<input name="txtSecond1" value="1">
<input name="txtSecond2" value="2">
<input name="txtSecond3" value="3">
<br>

<input name="txtThird1" value="1">
<input name="txtThird2" value="2">
<input name="txtThird3" value="3">
<br>

<button onclick="count()">计算</button>

<script>
function count()
{
var arr = ["txtFirst", "txtSecond", "txtThird"];
total = 0;

for(m=0; m<arr.length; m++)
{
for(i=1;;i++)
{
if(eval("document.all."+arr[m]+i))
{
o = eval("document.all."+arr[m]+i);
total += parseInt(o.value);
}
else
{
break;
}
}
}
alert(total);
}
</script>

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧