jquery 标签里的值相加怎么弄

zgm05060815 2012-01-04 06:16:23
<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"> 删除</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"> 删除</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"> 删除</a>
</li>
</ul>


如上,如何通过jquery算出总金额呢?各个li下有单价和数量
...全文
605 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgm05060815 2012-01-05
  • 打赏
  • 举报
回复
万分感谢。。解决了小弟头疼许久的问题,这个因为是在firefox的firebug里拷贝的,这些li是通过循环生成的,所以有相同id,不过也是个失误,刚才查了查,不能有相同的id,但可以有相同的name,基本功太欠缺火候,呵呵
lsw645645645 2012-01-05
  • 打赏
  • 举报
回复
发错了,不好意思。
lsw645645645 2012-01-05
  • 打赏
  • 举报
回复
$(function () {
$("html").click(function () {
$("#test:visible").hide();
});
});
p2227 2012-01-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zgm05060815 的回复:]

万分感谢。。解决了小弟头疼许久的问题,这个因为是在firefox的firebug里拷贝的,这些li是通过循环生成的,所以有相同id,不过也是个失误,刚才查了查,不能有相同的id,但可以有相同的name,基本功太欠缺火候,呵呵
[/Quote]看得出来。你如果需要id,可以添加一个循环变量,proid1什么的
p2227 2012-01-04
  • 打赏
  • 举报
回复
首先不可以有两个控件相同的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"> 删除</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"> 删除</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"> 删除</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>

87,914

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧