怎样用js统计一下的总价?ID是变化的,所以不能用ID来获取值然后相乘,价钱的ID一定包含lbPrice。数量的id一定包含txtAcount总价 =单价×数量想得到结果:2000×1+20000×1+2000×1
<tr style="background-color:#ffffff"> 
<td align="left"><span id="Repeater1_ctl01_lbName">三星2312</span></td>
<td align="left"><span id="Repeater1_ctl01_lbPrice">2000</span></td>
<td align="left">  <input name="Repeater1$ctl01$txtAcount" type="text" value="1" id="Repeater1_ctl01_txtAcount" class="number" /></td>

</tr>
<tr style="background-color:#ffffff"> 
                         <td align="left"><span id="Repeater1_ctl02_lbName">苹果2312445</span></td>
<td align="left"><span id="Repeater1_ctl02_lbPrice">20000</span></td>
<td align="left">  <input name="Repeater1$ctl02$txtAcount" type="text" value="1" id="Repeater1_ctl02_txtAcount" class="number" /></td>

<tr style="background-color:#ffffff"> 
<td align="left"><span id="Repeater1_ctl03_lbName">N75</span></td>
<td align="left"><span id="Repeater1_ctl03_lbPrice">2000</span></td>
<td align="left">  <input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number" /></td>

</tr>

解决方案 »

  1.   


    //在页面body后加个script标签,把这段代码放在里面
    var tb=document.getElementById("<%=Repeater1.ClientID %>");
    for(var i=0;i<tb.rows.length;i++) {//两个for循环如果有标题则改成从1开始循环
        tb.rows[i].cells[2].firstChild.onkeyup=function() {
            var total=0;
            for(var j=0,c,p;j<tb.rows.length;j++) {
                p=tb.rows[i].cells[1].firstChild.innerHTML-0,c=tb.rows[i].cells[2].firstChild.value-0;
                if(!isNaN(p) && !isNaN(c);
                    total+=p*c;
            }
            document.getElementById("total").innerHTML=total.toFixed(2);//指定要显示总价的id
        }
    }
      

  2.   

    <table id="tab">
    <tr style="background-color:#ffffff"> 
                                                    <td align="left"><span id="Repeater1_ctl01_lbName">三星2312</span></td>
        <td align="left"><span id="Repeater1_ctl01_lbPrice">2000</span></td>
        <td align="left">  <input name="Repeater1$ctl01$txtAcount" type="text" value="1" id="Repeater1_ctl01_txtAcount" class="number" /></td>
                                                                
    </tr>
    <tr style="background-color:#ffffff">                 
                                                                        <td align="left"><span id="Repeater1_ctl02_lbName">苹果2312445</span></td>
        <td align="left"><span id="Repeater1_ctl02_lbPrice">20000</span></td>
        <td align="left">  <input name="Repeater1$ctl02$txtAcount" type="text" value="1" id="Repeater1_ctl02_txtAcount" class="number" /></td>
                                                    
    <tr style="background-color:#ffffff"> 
                                                    <td align="left"><span id="Repeater1_ctl03_lbName">N75</span></td>
        <td align="left"><span id="Repeater1_ctl03_lbPrice">2000</span></td>
        <td align="left">  <input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number" /></td>
                                                    
    </tr></table>
    <script>
    var t = 0;
    var rows = document.getElementById("tab").rows;
    for(var i=0;i<rows.length;i++){
    var price = rows(i).cells(1).getElementsByTagName("SPAN")[0].innerText;
    var count = rows(i).cells(2).getElementsByTagName("INPUT")[0].value;
    t += price*count;
    }
    alert(t);
    </script>
      

  3.   

     for (var i=1; i <= ....length; i++)
         {
           document.getElementById('Repeater1_ctl0'+i+'_lbPrice').value)
    ......类推..document.getElementById('Repeater1$ctl0'+i+'$txtAcount').value)
    计算..
      

  4.   

    用jQuery
    var account = 0;
    $('span[id*=lbPrice]').each(function() {
      account += parseInt($(this).text()) * 
        parseInt($(this).parents('tr').find('input').val());
    });
    alert(account);
      

  5.   

    这样看看...<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Test</title>
    </head>
    <style type="text/css"> 
    body,td,div,input,fieldset,legend{font-family:Verdana; font-size:12px; color:#333333; font-weight:normal;}
    td{line-height:20px;}
    a:link,a:visited{font-family:Verdana; font-size:12px; color:#330099; font-weight:normal;  text-decoration:none;}
    a:hover,a:active{font-family:Verdana; font-size:12px; color:#FF6600; font-weight:normal; }
    span{font-family:Verdana; font-size:12px; color:red; font-weight:normal; display:block;}
    .cur01{background-color:#00CCFF; color:#FF3300; font-weight:bold;}
    </style>
    <script type="text/javascript" language="javascript">
    function calculate(){
    var likePriceID="lbPrice";  //价格包含的字符串
    var likeAcountID="txtAcount";  //数量包含的字符串
    var pList=document.getElementsByTagName("span");
    var aList=document.getElementsByTagName("input");
    var v=0;
    var total=0;
    for(var i=0;i<pList.length;i++){
    try{
    v=0;
    if(pList[i].id.indexOf(likePriceID)>0) v = parseInt(pList[i].innerHTML,10);
    if(aList[i].id.indexOf(likeAcountID)>0) v=v*parseInt(aList[i].value,10);
    }catch(e){}
    total+=v;
    }
    alert("总价为: "+total);
    }
    </script>
    <body>
    <table width="100%"  border="0">
    <tr style="background-color:#ffffff">                 
    <td align="left"><span id="Repeater1_ctl02_lbName">苹果2312445</span></td>
    <td align="left"><span id="Repeater1_ctl02_lbPrice">20000</span></td>
    <td align="left"><input name="Repeater1$ctl02$txtAcount" type="text" value="1" id="Repeater1_ctl02_txtAcount" class="number" /></td>
                                                    
    <tr style="background-color:#ffffff"> 
    <td align="left"><span id="Repeater1_ctl03_lbName">N75</span></td>
    <td align="left"><span id="Repeater1_ctl03_lbPrice">2000</span></td>
    <td align="left"><input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number" /></td>
    </tr>
    <tr style="background-color:#ffffff"> 
    <td align="left"><span id="Repeater1_ctl03_lbName">N75</span></td>
    <td align="left"><span id="Repeater1_ctl03_lbPrice">2000</span></td>
    <td align="left">  <input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number" /></td>
    </tr>
    </table>
    <input type="button" name="Submit" value="计算" onClick="javascript:calculate();">
    </body>
    </html>
      

  6.   

    有一个问题就是。当改变textbox的数量的时候。统计的数值还是按照原来的数量统计,修改数量不起作用
      

  7.   

    在文本框中加个onchange事件.去重新调下计算方法.
    也可以在下面做个按钮点击事件.调下计算方法.
      

  8.   

    无论怎样修改数字,那个value一直都是1 。
      

  9.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <META NAME="Author" CONTENT="">
      <META NAME="Keywords" CONTENT="">
      <META NAME="Description" CONTENT="">
     </HEAD> <BODY>
    <script type="text/javascript" language="javascript">
    function calculate(){
    var rows = document.getElementById("tab").rows;
    var t = 0;
    for(var i=0;i<rows.length;i++){
    var price = rows(i).cells(1).getElementsByTagName("SPAN")[0].innerText;
    var count = rows(i).cells(2).getElementsByTagName("INPUT")[0].value;
    t += price*count;
    }
    document.getElementById('sum').innerHTML = t;
    }
    </script>
    <body>
    <table width="100%"  border="0" id="tab">
    <tr style="background-color:#ffffff">                 
    <td align="left"><span id="Repeater1_ctl02_lbName">苹果2312445</span></td>
    <td align="left"><span id="Repeater1_ctl02_lbPrice">20000</span></td>
    <td align="left"><input name="Repeater1$ctl02$txtAcount" type="text" value="1" id="Repeater1_ctl02_txtAcount" class="number" onkeyup="calculate()" /></td>
                                                    
    <tr style="background-color:#ffffff"> 
    <td align="left"><span id="Repeater1_ctl03_lbName">N75</span></td>
    <td align="left"><span id="Repeater1_ctl03_lbPrice">2000</span></td>
    <td align="left"><input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number" 
    onkeyup="calculate()"/></td>
    </tr>
    <tr style="background-color:#ffffff"> 
    <td align="left"><span id="Repeater1_ctl04_lbName">N75</span></td>
    <td align="left"><span id="Repeater1_ctl04_lbPrice">2000</span></td>
    <td align="left">  <input name="Repeater1$ctl03$txtAcount" type="text" value="1" id="Repeater1_ctl03_txtAcount" class="number"
    onkeyup="calculate()"/></td>
    </tr>
    </table>
    <input type="button" name="Submit" value="计算" onClick="javascript:calculate();">
    <span id="sum"></span>
    </body>
    </html> </BODY>
    </HTML>
      

  10.   

    所有数量的input对象都加 onchange 事件,比如下面:<input name="Repeater1$ctl02$txtAcount" type="text" value="1"  onChange="javascript:calculate()" id="Repeater1_ctl02_txtAcount" class="number"/>
      

  11.   

    我不知道为什么不能感知数量变化,我是windows.open 打开购物车的页面的。