我需要一段可以实现显示商品折扣和节省了多少钱的代码,放在网页里面。多谢啦。

解决方案 »

  1.   

    你可以稍加修改
    <!doctype html public "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
    <head>
    <title>『CNLei's Blog』在线购物清单计算</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <meta http-equiv="Content-Language" content="zh-cn" />
    <meta name="Copyright" content="(c)WFCN.NET 2004-2005" />
    <meta name="Author" content="[email protected]" />
    <script type="text/javascript" language="javascript">
     <!--
    function sumPrice(curRow,totRows){ //计算价格
      var i,totMoney,totPro,totSort;
      totMoney=0;
      totSort=0;
      totPro=0;
      var myObj=document.getElementById("myProList")
      var myObjLen=document.getElementById("myProList").getElementsByTagName("tr").length
      var myChose=document.getElementById("Chose"+curRow);
      var myQuant=document.getElementById("Quant"+curRow);
      if (myChose.checked==true){
       myObj.rows(curRow).cells(4).innerText=myObj.rows(curRow).cells(3).innerText*myQuant.value;
      } else {
       myObj.rows(curRow).cells(4).innerText=0;
      }
      for (i=1;i<=totRows;i++) {
       totMoney+=eval(myObj.rows(i).cells(4).innerText);
       //alert(totSort);
       if (document.getElementById("Chose"+i).checked==true && document.getElementById("Quant"+i).value>0){
         totPro+=eval(document.getElementById("Quant"+i).value);
         totSort+=1;
       }
      }
      myObj.rows(totRows+1).cells(0).innerHTML="您选择购买了<strong>"+totSort+"</strong>种商品,共<strong>"+totPro+"</strong>件,总金额为:<strong>"+totMoney+"</strong>元。";
    } //-->
    </script>
    <style type="text/css" media="all">
    body  {text-align:center;margin:0px;padding:0px;font:normal 14px 宋体;background:#fff;}
    a,td,div,input,textarea,select {font:normal 14px 宋体;color:#333333;word-break:break-all;}
    form  {margin:0px;padding:0px;}
    .wrap {width:480px;padding:10px;}
    #title {text-align:left;}
    #title strong {color:blue;}
    #myProList {width:100%;padding:1px;text-align:center;border-top:1px #666 solid;border-left:1px #666 solid;}
    #myProList td {border-top:2px #fff solid;border-left:2px #fff solid;border-right:1px #bcbcbc solid;border-bottom:1px #bcbcbc solid;}
    #myProList .heading {padding:5px;background:#00cece url(background.gif) no-repeat fixed 0 0;}
    #myProList .heading td {border-top:1px #fff solid;border-left:1px #fff solid;border-right:1px #099 solid;border-bottom:1px #099 solid;}
    #myProList .rooting {padding:5px;text-align:left;}
    #myProList .rooting strong {color:#ff0000;}
    #myProList .rowA {}
    #myProList .rowB {background:#f6f6f6;}
    #myProList .pID {}
    #myProList .pName {}
    #myProList .Price {}
    #myProList .Quantity {}
    #myProList .inpuTxt {border:1px #999 solid;text-align:center;}
    </style><body>
    <div class="wrap">
    <div id="title">以下是您所选购的<strong>物品清单:</strong></div>
    <form method="post" action="">
    <table id="myProList" cellspacing="0" cellpadding="0">
    <tr class="heading">
      <td>商品编号</td>
      <td>商品名称</td>
      <td>数量(件)</td>
      <td>单价(元)</td>
      <td>合计(元)</td>
      <td>选择</td>
    </tr><tr class="rowB">  <td>265</td>
      <td>IBM-T40,14H笔记本</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant1" value="1" size="6" maxlength="4" onblur="sumPrice(1,10)" /></td>
      <td class="Price">14300</td>
      <td class="sumM">14300</td>
      <td><input type="checkbox" name="Chose" id="Chose1" value="1" onclick="sumPrice(1,10)" checked /></td>
    </tr><tr class="rowA">  <td>266</td>
      <td>IBM-T40,72笔记本</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant2" value="1" size="6" maxlength="4" onblur="sumPrice(2,10)" /></td>
      <td class="Price">14600</td>
      <td class="sumM">14600</td>
      <td><input type="checkbox" name="Chose" id="Chose2" value="1" onclick="sumPrice(2,10)" checked /></td>
    </tr><tr class="rowB">  <td>267</td>
      <td>IBM-X31(薄)笔记本</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant3" value="1" size="6" maxlength="4" onblur="sumPrice(3,10)" /></td>
      <td class="Price">12300</td>
      <td class="sumM">12300</td>
      <td><input type="checkbox" name="Chose" id="Chose3" value="1" onclick="sumPrice(3,10)" checked /></td>
    </tr><tr class="rowA">  <td>268</td>
      <td>SONY-V505BC </td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant4" value="1" size="6" maxlength="4" onblur="sumPrice(4,10)" /></td>
      <td class="Price">11900</td>
      <td class="sumM">11900</td>
      <td><input type="checkbox" name="Chose" id="Chose4" value="1" onclick="sumPrice(4,10)" checked /></td>
    </tr><tr class="rowB">  <td>269</td>
      <td>SONY-TR1</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant5" value="1" size="6" maxlength="4" onblur="sumPrice(5,10)" /></td>
      <td class="Price">15900</td>
      <td class="sumM">15900</td>
      <td><input type="checkbox" name="Chose" id="Chose5" value="1" onclick="sumPrice(5,10)" checked /></td>
    </tr><tr class="rowA">  <td>270</td>
      <td>SONY-GRT100</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant6" value="1" size="6" maxlength="4" onblur="sumPrice(6,10)" /></td>
      <td class="Price">11800</td>
      <td class="sumM">11800</td>
      <td><input type="checkbox" name="Chose" id="Chose6" value="1" onclick="sumPrice(6,10)" checked /></td>
    </tr><tr class="rowB">  <td>272</td>
      <td>IBM-X20超薄电脑</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant7" value="1" size="6" maxlength="4" onblur="sumPrice(7,10)" /></td>
      <td class="Price">5000</td>
      <td class="sumM">5000</td>
      <td><input type="checkbox" name="Chose" id="Chose7" value="1" onclick="sumPrice(7,10)" checked /></td>
    </tr><tr class="rowA">  <td>273</td>
      <td>IBM-X21超薄电脑</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant8" value="1" size="6" maxlength="4" onblur="sumPrice(8,10)" /></td>
      <td class="Price">5600</td>
      <td class="sumM">5600</td>
      <td><input type="checkbox" name="Chose" id="Chose8" value="1" onclick="sumPrice(8,10)" checked /></td>
    </tr><tr class="rowB">  <td>274</td>
      <td>IBM-X22超薄电脑</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant9" value="1" size="6" maxlength="4" onblur="sumPrice(9,10)" /></td>
      <td class="Price">6000</td>
      <td class="sumM">6000</td>
      <td><input type="checkbox" name="Chose" id="Chose9" value="1" onclick="sumPrice(9,10)" checked /></td>
    </tr><tr class="rowA">  <td>275</td>
      <td>DELL-500M笔记本</td>
      <td><input type="text" class="inpuTxt" name="Quant" id="Quant10" value="1" size="6" maxlength="4" onblur="sumPrice(10,10)" /></td>
      <td class="Price">9200</td>
      <td class="sumM">9200</td>
      <td><input type="checkbox" name="Chose" id="Chose10" value="1" onclick="sumPrice(10,10)" checked /></td>
    </tr><tr class="rooting">
      <td colspan="6">您选择购买了<strong>10</strong>种商品,共<strong>10</strong>件,总金额为:<strong>106600</strong>元。</td>
    </tr>
    </table>
    </form> 
    </div><!-- wrap end! --></body>
    </html>
      

  2.   

    唉,像这种问题,无非要么在sql语句中处理,要么在页面绑定的时候处理,反正你自己看怎么方便用什么方法就可以了
      

  3.   

    看来说的不准确。我需要的是显示出来这个商品的折扣,就是优惠价/原价,以及这样节省了多少钱,就是原价-优惠价。然后把他们嵌在网页中。sunjay117这位兄弟给的代码不少,可我发现没有实现这个功能。呵呵。
      

  4.   

    Sql语句
    select 原价,优惠价,(原价-优惠价) as '节省价' from 商品表
      

  5.   

    是直接把这句话放到页面里面就可以了?前后加个<p></p>
      

  6.   

    我直接把你节省了<%#select goodsmoney,goodsmoney2,(goodsmoney-goodsmoney2) as "moenysaved" from hishop_goods%>加在原来的代码后面是不是就可以了?这里的goodsmoney,goodsmoney2是系统本来就有的,moneysaved是我新加的。改怎么声明呢?====================================================================================
    <asp:Literal id="goodsmoney2" Runat="server"></asp:Literal>你节省了<%#select goodsmoney,goodsmoney2,(goodsmoney-goodsmoney2) as "moneysaved" from hishop_goods%>
      

  7.   

    我直接把你节省了<%#select goodsmoney,goodsmoney2,(goodsmoney-goodsmoney2) as "moenysaved" from hishop_goods%>加在原来的代码后面是不是就可以了?这里的goodsmoney,goodsmoney2是系统本来就有的,moneysaved是我新加的。改怎么声明呢?====================================================================================
    <asp:Literal id="goodsmoney2" Runat="server"></asp:Literal>你节省了<%#select goodsmoney,goodsmoney2,(goodsmoney-goodsmoney2) as "moneysaved" from hishop_goods%>你要用先在数据库中读出来,用datareader或dataSet都可以,然后将控件的数据源设置为dataReader或者DataSet,然后绑定就可以了