你参考一下网上算你能买多大的楼房的网页,应该对你有帮助。我在sina.com.cn上看到过。我对这个挺感兴趣的,我没事的时候坐一下。^_^

解决方案 »

  1.   

    给的分太少了,我可以费了好的的力气才写完并加测试。一下为源代码:
    <!-- #include file ="../includes/conn.asp" -->  <!--这是我的conn-->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>在线销售</title>
    <SCRIPT language=javaScript src="../includec/check.js"></SCRIPT>
    </head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function GetDelNum(inti){
    var delNum,addNum,sumPrice,intj;
    delNum=eval("document.all.frm1.txtGoods_Nums"+inti);
    if(IsPos(delNum.value==false)){
    alert("购买数量不符合要求!");
    delNum.focus();
    delNum.select();
    return false;
    }
    var intTemp=delNum.value-1;
    if(IsPos(intTemp)==false){
    if(intTemp==1){
    delNum.value=intTemp
    return true;
    }
    else{
    alert("购买数量不符合要求!");
    delNum.focus();
    delNum.select();
    return false;
    }
    }
    delNum.value=intTemp;
    sumPrice=0;
    intj=0;
    var fltPrice,intGoods_Nums;
    for(i=1;i<document.all.frm1.hidRecordset.value;i++){ fltPrice=eval("document.all.frm1.hidPrice"+i);
    intGoods_Nums=eval("document.all.frm1.txtGoods_Nums"+i); sumPrice=sumPrice+(fltPrice.value)*(intGoods_Nums.value);
    if(intGoods_Nums.value==0){
    sumPrice=sumPrice-(fltPrice.value)*(intGoods_Nums.value);
    }
    //alert(intGoods_Nums.value);
    }
    document.all.frm1.txtSumPrice.value=sumPrice;
    }
    function GetGoodsNum(inti,intValue){
    sumPrice=0;
    intj=0;
    var fltPrice,intGoods_Nums;
    for(i=1;i<document.all.frm1.hidRecordset.value;i++){ fltPrice=eval("document.all.frm1.hidPrice"+i);
    intGoods_Nums=eval("document.all.frm1.txtGoods_Nums"+i); sumPrice=sumPrice+(fltPrice.value)*(intGoods_Nums.value);

    document.all.frm1.txtSumPrice.value=sumPrice;
    }
    }
    //-->
    </SCRIPT>
    <body>
    <form name="frm1" method="post" action="">
      <table width="100%" border="0">
        <tr>
          <td width="6%">ID</td>
          <td width="41%">名称</td>
          <td width="12%">点数</td>
          <td width="8%">金额</td>
          <td width="33%" align="center">数量</td>
        </tr>
    <%
             '这是我的临时表,字段为goods_ID,goods_Name,goods_Numd(点数),goods_Nums(数量),goods_price(价格)
    strSql="select * from Tb_goods where goods_delFlag=0 order by goods_ID"
    rs.open strSql,conn,1,1
    Dim inti
    inti=1
    if not rs.eof then
    do while not rs.eof  %>
        <tr>
          <td><%=inti%></td>
          <td><%=rs("goods_Name")%></td>
          <td><%=rs("goods_Numd")%></td>
          <td><%=rs("goods_price")%>
      <INPUT TYPE="hidden" name="hidPrice<%=inti%>" value="<%=rs("goods_price")%>">
      </td>
          <td><table width="100%" border="0">
              <tr> 
                <td width="12%"><input type="button" name="delNum" value="-" onclick="GetDelNum(<%=inti%>)"></td>
                <td width="59%"><input name="txtGoods_Nums<%=inti%>" type="text" value="0" onchange="GetGoodsNum(<%=inti%>,this.value)"></td>
                <td width="29%"><input type="button" name="addNum" value="+" onclick="GetaddNum()"></td>
              </tr>
            </table></td>
        </tr>
        <%
    inti=inti+1
    rs.movenext
    loop
    end if
    rs.close
    %>
    <INPUT TYPE="hidden" name="hidRecordset" value="<%=(inti)%>">
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>总金额</td>
          <td><input name="txtSumPrice" type="text" value="0">
            元</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td><input type="submit" name="Submit3" value="购买"></td>
          <td><INPUT TYPE="reset"></td>
          <td>&nbsp;</td>
        </tr>
      </table>
      <p><font color="#FF0000">上面全是动态的.</font></p>
      <p><font color="#FF0000">所有商品都有一个ID. 按购买后.要知道用户购买了一张&quot;商品A&quot; 点卡,二张&quot;商品C&quot; 
        .</font></p>
      <p><font color="#FF0000">也就是说有ID=1 一张,ID=3 的二张.后台数据库记录这些信息.</font></p>
    </form>
    </body>
    </html>
    <!--
    一点不足:
    当数量为一个的时候,无法实现减为零
    没有时间完成添加的那部分,你参考一下减的方式,做好了。
    -->
      

  2.   

    忘了给你这个javascript的函数了
    function IsPos(str){
    var i,strlength,tempchar; str=CStr(str);
    if(str=="") return false;
    if(parseInt(str)==0) return false;
    strlength=str.length;
    for(i=0;i<strlength;i++){
    tempchar=str.substring(i,i+1);
    if(!(tempchar==0||tempchar==1||tempchar==2||tempchar==3||tempchar==4||tempchar==5||tempchar==6||tempchar==7||tempchar==8||tempchar==9)){
    return false;
    }

    }
    return true;
    }
    还有就是,在函数function GetGoodsNum()中,做想if(IsPos(delNum.value==false))这个的判断了。