国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算

瀏覽:442日期:2022-06-11 15:15:28

本文實(shí)例為大家分享了商品價(jià)格計(jì)算的具體代碼,利用ajax和php實(shí)現(xiàn)以下頁(yè)面

index.php

<!DOCTYPE html><html><head> <meta charset="utf-8" /> <title>商品價(jià)格計(jì)算</title> <style type="text/css"> table { border-collapse: collapse; } tr { text-align: center; } .a4 { text-align: right; /* padding-right: 15px; */ } #myDiv { color: red; } input { border: 0; } </style></head><body> <form action="data.php" method="get"> <table border="1" bordercolor="#00CCCC" cellpadding="20"> <tr> <th>商品名稱</th> <th>購(gòu)買數(shù)量(斤)</th> <th>商品價(jià)格(元/斤)</th> </tr> <tr> <td>香蕉</td> <td><input type="text" name="a1" value="0" id="n1" onchange="zongji()" /></td> <td>8</td> </tr> <tr> <td>蘋(píng)果</td> <td><input type="text" name="a2" value="0" id="n2" onchange="zongji()" /></td> <td>5</td> </tr> <tr> <td>橘子</td> <td><input type="text" name="a3" value="0" id="n3" onchange="zongji()" /></td> <td>7</td> </tr> <tr> <td colspan="3">商品折扣:<span>0.8</span></td> </tr> <tr> <td colspan="3">  <div id="jiage">打折后購(gòu)買商品總價(jià)格: 元</div> </td> </tr> </table> </form> <script> function zongji() { var b1 = document.getElementById("n1").value; var b2 = document.getElementById("n2").value; var b3 = document.getElementById("n3").value; //1.創(chuàng)建對(duì)象 var xmlhttp; if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 瀏覽器執(zhí)行代碼 xmlhttp = new XMLHttpRequest(); } else { // IE6, IE5 瀏覽器執(zhí)行代碼 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } //2.判斷對(duì)象是否準(zhǔn)備就緒 xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {  document.getElementById("jiage").innerHTML = xmlhttp.responseText; } }; //3.發(fā)出請(qǐng)求 xmlhttp.open( "GET", "demo.php?c1=" + b1 + "&c2=" + b2 + "&c3=" + b3, true ); xmlhttp.send(); } </script></body></html>

data.php

<p> <?php $d1 = $_GET["c1"]; $d2 = $_GET["c2"]; $d3 = $_GET["c3"]; $sum = (intval($d1) * 8 + intval($d2) * +intval($d3) * 7) * 0.8; // $sum=$a1*7.99+$a2*6.89+$a3*3.99; echo "打折后購(gòu)買商品總價(jià)格: $sum 元"; ?></p>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持。

標(biāo)簽: Ajax
主站蜘蛛池模板: 利川市| 茶陵县| 浠水县| 白玉县| 连山| 兰州市| 临沧市| 浪卡子县| 甘泉县| 老河口市| 潢川县| 新兴县| 白水县| 涡阳县| 乳源| 南华县| 朝阳县| 九龙城区| 砚山县| 郸城县| 吉林市| 左贡县| 咸宁市| 德钦县| 连山| 朝阳市| 昌乐县| 刚察县| 吕梁市| 绥中县| 镇赉县| 宣化县| 扎鲁特旗| 中卫市| 金乡县| 谷城县| 泸水县| 泗阳县| 监利县| 昌都县| 钟山县|