html js 改变文本框的值,jsp用js设定文本框的值

此博客介绍了一段使用HTML和JavaScript编写的计价表格,用户可以通过选择商品并输入数量,实时计算总价。适合初学者了解表单交互和基础前端计算功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在仔细阅读了你的问题后,帮你写了一个,不知道符合你的要求不。

我用html+js写的,关于后台的变量的接收由你自己完成。

html代码(复制到记事本后另存为以.html为后缀的文件,再到浏览器中打开看效果):

htmlhead

script language=javascript

function countAll(o){

var sum=0;

for(var i=1;i=3;i++){

eval(if(o.c + i + .checked)sum+=o.j+i+.value*o.s+i+.value;);

}

o.zong.value=sum;

}/script

/headbody

table cellspacing=0 cellpadding=0 border=1px bordercolor=#0033FF bordercolordark=#FFFF00 style=margin:1px;padding:1px;text-align:center;font:12px;word-wrap:normal;word-break:keep-all;overflow:visible; align=center

form action= method=get

tr

td width=95 rowspan=2input name=c1 type=checkbox id=c1 value=1

物品1/td

td width=319价格:

input name=j1 type=text id=j1 readonly value=20/td

/tr

tr

td数量:

input name=s1 type=text id=s1/td

/tr

tr

td rowspan=2input name=c2 type=checkbox id=c2 value=1

物品2/td

td价格:

input name=j2 type=text id=j2 readonly value=50/td

/tr

tr

td数量:

input name=s2 type=text id=s2/td

/tr

tr

td rowspan=2input name=c3 type=checkbox id=c3 value=1

物品3/td

td价格:

input name=j3 type=text id=j3 readonly value=10/td

/tr

tr

td数量:

input name=s3 type=text id=s3/td

/tr

tr

tdinput name=count type=button value=计算总价 onclick=countAll(this.form)/tdtd总价:input name=zong type=text id=zong/td/trtrtd colspan=2input name=submit type=submit id=submit value=提交 input name=reset type=reset id=reset value=重置/td

/tr/tr/form/table

/body/html

取消

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值