87,917
社区成员
发帖
与我相关
我的任务
分享
jQuery(function($) {
var sum = 0;
var asum = $("input[id^='asum']");
asum.each(function(){
sum += parseFloat( $(this).val());
});
alert(sum);
});
<html>
<head>
<title>Test</title>
<script type="text/javascript">//<![CDATA[
window.onload = function(){
var obj = document.getElementsByTagName("input");
var iTotal = 0;
for(var i = 0; i < obj.length; i++){
iTotal += +obj[i].value;
}
alert(iTotal);
}
//]]></script>
</head>
<body>
<input type="text" value="1" />
<input type="text" value="2" />
<input type="text" value="3" />
<input type="text" value="4" />
</body>
</html>
var val=0;
for(var i=0;;i++){
if(document.getElementById("asum"+i)){
val+=document.getElementById("asum"+i).value;
}else{
break;
}
}