<br><div class="msgheader"> <div class="right"><span style="CURSOR: pointer" onclick="copycode(getid('phpcode35'));"><u>复制代码</u></span></div>代码如下:</div> <div class="msgborder" id="phpcode35"> <br> <br> <br><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <br> <br><title>打折后价格计算</title> <br><!-- 设置计算价格事件函数,取不同下拉打折数,计算结果送入文字框--> <br><script type="text/javascript"> <br />function calculator(){ <br />var prices=document.getElementById("price"); <br />var discounts=document.getElementById("number"); <br />var pay; <br />var select=document.getElementById("payfunction"); <br />if((prices.value>=0&&!isNaN(prices.value))&&(discounts.value>=0&&!isNaN(discounts.value))&&prices.value!=""&&discounts.value!="") <br />{ <br />pay=prices.value*discounts.value; <br />switch(parseInt(select.value)){ <br />case 1:pay=pay*0.5; break; <br />case 2:pay=pay*0.8; break; <br />case 3:pay=pay*0.6; break; <br />} <br />document.getElementById("result").value=pay; <br />alert("恭喜你,交易成功!"); <br />}else <br />{ <br />prices.focus(); <br />prices.select(); <br />alert("请输入正确的价格和数量(也不能为空)!"); <br />} <br />} <br /></script> <br> <br><!-- 定义界面格式,设置下拉表,设置计算价格事件--> <br> <br><center> <br><form name="discount" action="result.jsp" method="post"> <br>竞拍价格:<input type="text" id="price" style="width: 150px"><br> <br>购买数量:<input type="text" id="number" style="width: 150px"><br> <br>支付方式:<select id="payfunction" style="width: 150px"> <br><option value="1">网银支付-打5折</option> <br><option value="2">支付宝支付-打8折</option> <br><option value="3" selected>Q币支付-打6折</option> <br></select><br> <br>预计总价:<input type="text" id="result" style="width: 150px"><br> <br><input type="button" id="allresult" value="计算总价" onclick="calculator()"> <br> </form> <br> </center> <br> <br> <br> </div>