HTML折扣测算价钱完成基本原理与脚本制作编码


拷贝编码
编码以下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<meta http-equiv="content-type" content="text/html; charset=UTF⑻">
<head>
<title>折扣后价钱测算</title>
<!-- 设定测算价钱恶性事件涵数,取不一样往下拉折扣数,测算結果送入文本框-->
<script type="text/javascript">
function calculator(){
var prices=document.getElementById("price");
var discounts=document.getElementById("number");
var pay;
var select=document.getElementById("payfunction");
if((prices.value>=0&&!isNaN(prices.value))&&(discounts.value>=0&&!isNaN(discounts.value))&&prices.value!=""&&discounts.value!="")
{
pay=prices.value*discounts.value;
switch(parseInt(select.value)){
case 1:pay=pay*0.5; break;
case 2:pay=pay*0.8; break;
case 3:pay=pay*0.6; break;
}
document.getElementById("result").value=pay;
alert("恭贺你,买卖取得成功!");
}else
{
prices.focus();
prices.select();
alert("请键入正确的价钱和数量(也不可以为空)!");
}
}
</script>
</head>
<!-- 界定页面文件格式,设定往下拉表,设定测算价钱恶性事件-->
<body>
<center>
<form name="discount" action="result.jsp" method="post">
竞拍价钱:<input type="text" id="price" style="width: 150px"/>

选购数量:<input type="text" id="number" style="width: 150px"/>

付款方法:<select id="payfunction" style="width: 150px">
<option value="1">网银付款-打5折</option>
<option value="2">付款宝付款-打8折</option>
<option value="3" selected="true">Q币付款-打6折</option>
</select>

预计总价:<input type="text" id="result" style="width: 150px">

<input type="button" id="allresult" value="测算总价" onclick="calculator()" />
</form>
</center>
</body>
</html>