jquery 如何把每个div中span下的数字相加
如题<divclass="dd"><spanclass="dd_s">1</span></div><divclass="dd"><spanclass="dd_s">2</...
如题
<div class="dd">
<span class="dd_s"> 1 </span>
</div>
<div class="dd">
<span class="dd_s"> 2</span>
</div>
<div class="dd">
<span class="dd_s"> 10 </span>
</div>
如何加获取值在相加然后存在一个变量中! 展开
<div class="dd">
<span class="dd_s"> 1 </span>
</div>
<div class="dd">
<span class="dd_s"> 2</span>
</div>
<div class="dd">
<span class="dd_s"> 10 </span>
</div>
如何加获取值在相加然后存在一个变量中! 展开
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>相加_独占网络</title>
<script type="text/javascript" src="http://www.sz886.com/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var sum=0;
$.each($(".dd span"),function(index,item){
//如果数字有小数点,就使用 parsetFloat()
sum+= parseInt($.trim($(item).text()));
});
alert(sum);
});
</script>
</head>
<body>
<div class="dd">
<span class="dd_s"> 1 </span>
</div>
<div class="dd">
<span class="dd_s"> 2</span>
</div>
<div class="dd">
<span class="dd_s"> 10 </span>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>相加_独占网络</title>
<script type="text/javascript" src="http://www.sz886.com/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var sum=0;
$.each($(".dd span"),function(index,item){
//如果数字有小数点,就使用 parsetFloat()
sum+= parseInt($.trim($(item).text()));
});
alert(sum);
});
</script>
</head>
<body>
<div class="dd">
<span class="dd_s"> 1 </span>
</div>
<div class="dd">
<span class="dd_s"> 2</span>
</div>
<div class="dd">
<span class="dd_s"> 10 </span>
</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询