怎样用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>
<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>
解决方案 »
- mootools中(function(){})();与function(){}的区别是什么
- showmodelessdialog的help参数的问题(帮助按钮)
- 如何实现做一些代码发到网站上后,无需修改原网站内容,即可实现把所有网页上某个词变成链接文字
- 求助iframe连续打印序号错乱问题!
- 关于Aptana不能调试的问题
- checkbox状态
- 雪地跪求一个jquery或js问题。在线等待,高手进。
- 请教如何实现table中background的变幻
- Iframe自动调整高度出现的Iframe页下部空白过多的问题
- 急急急,请问一般的网页链接里面的加密的参数是怎么实现的?
- ajax 读取聊天室 发现内存一直涨下去 ????
- js 怎么调用 浏览器的 “文件”->“页面设置”功能
//在页面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
}
}
<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>
{
document.getElementById('Repeater1_ctl0'+i+'_lbPrice').value)
......类推..document.getElementById('Repeater1$ctl0'+i+'$txtAcount').value)
计算..
var account = 0;
$('span[id*=lbPrice]').each(function() {
account += parseInt($(this).text()) *
parseInt($(this).parents('tr').find('input').val());
});
alert(account);
"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>
也可以在下面做个按钮点击事件.调下计算方法.
<!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>