<input name="textfield" type="text" id="TruePrice" width="30px" maxlength="10" onchange="GetPrice()" />
打折:
<select name="select" id="zhe" onchange="GetPrice()">
<option value="one">一折</option>
<option value="five">五折</option>
<option value="seven">七折</option>
<option value="eight">八折</option>
<option value="nine">九折</option>
</select>
实收金额:
<input name="textfield2" type="text" id="Discount" width="30px" maxlength="10" />
因无开发工具就写了JS
<script type="text/javascript">
function GetPrice()
{
var TruePrice=document.getElementById("TruePrice").value//应收金额
var Zhe=document.getElementById("zhe")//打折
var calue=Zhe.options[Zhe.selectedIndex].text
switch (calue)
{case "一折":
calue="0.1"
break
case "五折":
calue="0.5"break
case "七折":
calue="0.7"break
case "八折":
calue="0.8"break
case "九折":
calue="0.9"break
}
var a=Number(calue)*Number(TruePrice)
document.getElementById("Discount").value=a//实收金额
}
</script>族物
在C#的开发环境中可则亏以在打折这个下拉孙穗神框的一个Select事件中进行计算
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>MyHtml2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/htmlcharset=UTF-8">
<script>
/*
*@author Caoshun
*@计算 合计费用
*/
function countMethod(){
var num=document.getElementById("num").value
var unitPrice=document.getElementById("unitPrice").value
var freight=document.getElementById("freight").value
document.getElementById("result"顷销做).value=parseFloat((num*unitPrice))+parseFloat(freight)
}
</script>
</head>
<body>
<table border="1" cellpadding="1" cellspacing="1" background="#red" style="text-align: center">
<tr><td colspan="5" align="center">简易购物车</td></tr>
<tr>
<td>商品名称</td>
<td>数量(件)</td>
<td>单价(美元斗扒)</雀衡td>
<td>运费(美元)</td>
<td><input type="button" value="合计" onclick="countMethod()"></td>
</tr>
<tr>
<td>跑跑道具</td>
<td><input type="text" size="6" id="num"></td>
<td><input type="text" size="6" id="unitPrice"></td>
<td><input type="text" size="6" id="freight"></td>
<td><input type="text" size="6" id="result"></td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
<style>
fieldset{
margin:0 auto
width:800px
}
legend{
color:red
}
table{
margin:0 auto
width: 400px
border-collapse:collapse
}
td{
border:1px solid 察慧乱gray
}
</style>
<title>第三题</title>
<script>
var Shop = function(xm, mc, sl, dj, fs){
this.xm = xm
this.mc = mc
this.sl = sl
this.dj = dj
this.fs = fs
}
Shop.prototype.toString = function(){
return ("客户姓名:" + this.xm
+ "\n商品败档名称: " + this.mc
+ "\n购买数量:" + this.sl
+ "\n购买单价:" + this.dj + "元"
+ "\n邮购方式:" + this.fs
+ "\n总价:" + this.sl * this.dj + "元")
}
var buy = function(fm){
var xm = fm.xm.value.replace(/^\s+|\s+$/,"")
var 碧粗mc = fm.mc.value
var sl = fm.sl.value.replace(/\D/g,"")
var dj = fm.dj.value
var fs = fm.fs.value
if(xm == ""){
alert("填写好客户姓名!")
fm.xm.focus()
return false
}else if(sl == ""){
alert("填写好购买数量!")
fm.sl.focus()
fm.sl.select()
return false
}else if(dj == ""){
alert("填写好购买单价!")
fm.dj.focus()
return false
}
var sp = new Shop(xm, mc, sl, dj, fs)
alert(sp)
return true
}
onload = function(){
var arr = [26.0, 30, 22]
fm.mc.onchange = function(){
fm.dj.value = arr[this.selectedIndex].toFixed(1)
}
fm.dj.value = arr[0].toFixed(1)
}
</script>
</head>
<body>
<fieldset>
<legend>
网上购物>>>网上商店
</legend>
<form name="fm" onsubmit="return buy(this)">
<table>
<tr>
<td>客户姓名:</td>
<td>
<input type="text" name="xm" />
</td>
</tr>
<tr>
<td>商品名称:</td>
<td>
<select name="mc">
<option>高等数学</option>
<option>汇编语言</option>
<option>JavaScript编程</option>
</select>
</td>
</tr>
<tr>
<td>购买数量:</td>
<td><input type="text" name="sl" /></td>
</tr>
<tr>
<td>购买单价:</td>
<td>
<input name="dj" type="text" readonly="readonly" />
</td>
</tr>
<tr>
<td>邮购方式:</td>
<td>
<label><input type="radio" name="fs" value="平邮" checked="true" />平邮</label>
<label><input type="radio" name="fs" value="挂号"/>挂号</label>
<label><input type="radio" name="fs" value="EMS" />EMS</label>
</td>
</tr>
<tr>
<td colspan=2 style="text-align:center">
<input type="submit" value="现在购买" />
<input type="reset" value="重写订单" />
</td>
</tr>
</table>
</form>
</fieldset>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)