日期:2014-05-16  浏览次数:20480 次

jquery 计算问题
计算所有<DIV ID="price"></DIV>的总和


------解决方案--------------------
引用:
我不是alert出来,我要返回到某个DIV中,应该怎么写 比如<div class="totalprice">xxx</div>


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var sum = 0;
            $("#price div").each(function (i, k) {
                sum += parseFloat($(this).html());
            })
            $(".totalprice").html(sum);
        })
    </script>
</head>
<body>
   <form id="form1" runat="server">
   <div id="price">
       <div>100</div>
       <div>150</div>
       <div>180</div>
   </div>
   <div style="color:Red;" class="totalprice"></div> 
    </form>
</body>
</html>