$0.0">
这是我的设置。
<input type="checkbox" name="item1" value="100" class="100" />
<input type="checkbox" name="item2" value="200" class="200" />
<input type="checkbox" name="item3" value="300" class="300" />
<p>$0.00</p>
我需要的条件是:将P tag更改为在复选框中选中的金额如果选中了1个以上的复选框,则将该金额添加到一起并显示在P tag中如果1个或多个复选框未选中,则减去该金额并在P tag中显示如果没有选中或全部未选中,则在P tag中显示零。
到目前为止,我只有这个,但很明显,它只显示被选中框的价格,并且当我取消选中框时,它不会添加,也不会删除。
$("input[type=checkbox]").click(function() {
var amount = $(this).attr("class");
$("p").html("$"+amount);
});
感谢任何人的帮助!
发布于 2010-12-21 04:10:49
简单的尝试..。
$("input[type=checkbox]").change(function() {
var amount = 0;
$("input[type=checkbox]:checked").each(function(){
amount += parseFloat(this.value,10);
});
$("p").html("$"+amount);
});
https://stackoverflow.com/questions/4496172
复制相似问题