
如何用JS实现2个数相乘
我想输入一个数量,在另外的地方自动会跳出总价数量*单价=总价单价是固定的值比方说60JS高手们都解答一下吧...
我想输入一个数量,在另外的地方自动会跳出总价
数量*单价=总价 单价是固定的值 比方说60
JS高手们都解答一下吧 展开
数量*单价=总价 单价是固定的值 比方说60
JS高手们都解答一下吧 展开
2个回答
2008-03-14
展开全部
用onkeyup效果能好点吧 一下
---------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function account()
{
var a=document.all.a.value;
var b=document.all.b.value;
var c=a*b;
document.all.c.value=c;
}
</script>
<body>
单价:<input id="a" type="text" value="60">
数量:<input id="b" type="text" onkeyup="account()">
总和 <input id="c" type="text">
<input type="button" onclick="account()" value="计算">
</body>
</html>
---------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function account()
{
var a=document.all.a.value;
var b=document.all.b.value;
var c=a*b;
document.all.c.value=c;
}
</script>
<body>
单价:<input id="a" type="text" value="60">
数量:<input id="b" type="text" onkeyup="account()">
总和 <input id="c" type="text">
<input type="button" onclick="account()" value="计算">
</body>
</html>
展开全部
例:
<form>
数量:<input type="text" name="size" onchage="setValue(this.form)">
单价:<input type="text" name="price">
总价:<input type="text" name="count">
</form>
<script>
function setValue(form){
if(form.size.value != "" && form.price.value !=""){
form.count.value=form.size.value*form.count.value;
}
}
</script>
<form>
数量:<input type="text" name="size" onchage="setValue(this.form)">
单价:<input type="text" name="price">
总价:<input type="text" name="count">
</form>
<script>
function setValue(form){
if(form.size.value != "" && form.price.value !=""){
form.count.value=form.size.value*form.count.value;
}
}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询