<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; >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> <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><br> </div>