首页 > 编程 > JS > 正文

已知商品单价,用JS计算所选数量的总价

2020-09-19 11:07:50
字体:
来源:转载
供稿:网友

晚上一个网友要我帮忙写个js算法,虽然自己的js不是很好,不过题目也算简单,想了半小时就出来了,要求是:定义商品的价格,然后通过选择下拉菜单的数量,得到商品总价.代码如下:

 

<!doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>hello,yang</title>
</head>

<body>
<script type="text/javascript">
function change(a){
var newp = 200*a
var price = document.getelementbyid("price");
price.setattribute("value",newp)
}
</script>
<select onchange="change(this.value)">
  <option value=1>1</option>
  <option value=2>2</option>
  <option value=3>3</option>
</select><input type="text" value="200" id=price>
</body>
</html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表