<ul id="products">
<li>
<input id="proid" class="text_short ui-widget-content ui-corner-all" type="hidden" value="401" maxlength="15" name="proid">
<input id="proname" class="text_short ui-widget-content ui-corner-all" type="text" value="联想G470AH-IFI 14.0英寸笔记本电脑" maxlength="15" name="proname">
<input id="procount" class="text_price ui-widget-content ui-corner-all" type="text" value="5" maxlength="15" name="procount">
<input id="proprop" class="text_short ui-widget-content ui-corner-all" type="text" value="颜色:深棕色" maxlength="15" name="proprop">
<input id="price" class="text_price ui-widget-content ui-corner-all" type="text" value="4439" maxlength="15" name="price">
<a class="remove" href="#nogo">&nbsp;删除</a>
</li>
<li>
<input id="proid" class="text_short ui-widget-content ui-corner-all" type="hidden" value="1091" maxlength="15" name="proid">
<input id="proname" class="text_short ui-widget-content ui-corner-all" type="text" value="美国森泰斯(sumdex)FullSpeed流线15.6寸电脑背包PON-372BK" maxlength="15" name="proname">
<input id="procount" class="text_price ui-widget-content ui-corner-all" type="text" value="1" maxlength="15" name="procount">
<input id="proprop" class="text_short ui-widget-content ui-corner-all" type="text" value="undefined" maxlength="15" name="proprop">
<input id="price" class="text_price ui-widget-content ui-corner-all" type="text" value="218" maxlength="15" name="price">
<a class="remove" href="#nogo">&nbsp;删除</a>
</li>
<li>
<input id="proid" class="text_short ui-widget-content ui-corner-all" type="hidden" value="404" maxlength="15" name="proid">
<input id="proname" class="text_short ui-widget-content ui-corner-all" type="text" value="戴尔Inspiron13Z 13英寸笔记本电脑" maxlength="15" name="proname">
<input id="procount" class="text_price ui-widget-content ui-corner-all" type="text" value="1" maxlength="15" name="procount">
<input id="proprop" class="text_short ui-widget-content ui-corner-all" type="text" value="颜色:银色" maxlength="15" name="proprop">
<input id="price" class="text_price ui-widget-content ui-corner-all" type="text" value="4659" maxlength="15" name="price">
<a class="remove" href="#nogo">&nbsp;删除</a>
</li>
</ul>如上,如何通过jquery算出总金额呢?各个li下有单价和数量

解决方案 »

  1.   

    首先不可以有两个控件相同的id
    再就是容错这些东西你自己写<body>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.4.2.min.js"></script><ul id="products">
    <li>
    <input class="text_short ui-widget-content ui-corner-all" type="hidden" value="401" maxlength="15" name="proid">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="联想G470AH-IFI 14.0英寸笔记本电脑" maxlength="15" name="proname">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="5" maxlength="15" name="procount">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="颜色:深棕色" maxlength="15" name="proprop">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="4439" maxlength="15" name="price">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="" maxlength="15" name="sum_price">
    <a class="remove" href="#nogo">&nbsp;删除</a>
    </li>
    <li>
    <input class="text_short ui-widget-content ui-corner-all" type="hidden" value="1091" maxlength="15" name="proid">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="美国森泰斯(sumdex)FullSpeed流线15.6寸电脑背包PON-372BK" maxlength="15" name="proname">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="1" maxlength="15" name="procount">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="undefined" maxlength="15" name="proprop">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="218" maxlength="15" name="price">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="" maxlength="15" name="sum_price">
    <a class="remove" href="#nogo">&nbsp;删除</a>
    </li>
    <li>
    <input class="text_short ui-widget-content ui-corner-all" type="hidden" value="404" maxlength="15" name="proid">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="戴尔Inspiron13Z 13英寸笔记本电脑" maxlength="15" name="proname">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="1" maxlength="15" name="procount">
    <input class="text_short ui-widget-content ui-corner-all" type="text" value="颜色:银色" maxlength="15" name="proprop">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="4659" maxlength="15" name="price">
    <input class="text_price ui-widget-content ui-corner-all" type="text" value="" maxlength="15" name="sum_price">
    <a class="remove" href="#nogo">&nbsp;删除</a>
    </li>
    </ul>
    <input type="button" value="计算" id="Cal"/><script type="text/javascript">
    $("#Cal").click(function(){
    $("#products li").each(function(){
    $(":input[name=sum_price]",this).val(parseInt($(":input[name=procount]",this).val())*parseFloat($(":input[name=price]",this).val()))
    })
    });
    </script>
      

  2.   

    $(function () {
               $("html").click(function () {
                   $("#test:visible").hide(); 
               }); 
           });
      

  3.   

    万分感谢。。解决了小弟头疼许久的问题,这个因为是在firefox的firebug里拷贝的,这些li是通过循环生成的,所以有相同id,不过也是个失误,刚才查了查,不能有相同的id,但可以有相同的name,基本功太欠缺火候,呵呵
      

  4.   

    看得出来。你如果需要id,可以添加一个循环变量,proid1什么的