<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <head> <title>打折后價(jià)格計(jì)算</title> <!-- 設(shè)置計(jì)算價(jià)格事件函數(shù),取不同下拉打折數(shù),計(jì)算結(jié)果送入文字框--> <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("請(qǐng)輸入正確的價(jià)格和數(shù)量(也不能為空)!"); } } </script> </head> <!-- 定義界面格式,設(shè)置下拉表,設(shè)置計(jì)算價(jià)格事件--> <body> <center> <form name="discount" action="result.jsp" method="post"> 競(jìng)拍價(jià)格:<input type="text" id="price" style="width: 150px"/> 購買數(shù)量:<input type="text" id="number" style="width: 150px"/> 支付方式:<select id="payfunction" style="width: 150px"> <option value="1">網(wǎng)銀支付-打5折</option> <option value="2">支付寶支付-打8折</option> <option value="3" selected="true">Q幣支付-打6折</option> </select> 預(yù)計(jì)總價(jià):<input type="text" id="result" style="width: 150px"> <input type="button" id="allresult" value="計(jì)算總價(jià)" onclick="calculator()" /> </form> </center> </body> </html>
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com