我的代码有问题。它不会对复选框的所有值求和。这里有什么问题?
我已经尝试了所有方法,但它不会显示任何东西。
HTML
<div id='vizitkarte'>
<h2>Vizītkarte</h2>
<input id='cheackbox_pam_viz' type="checkbox" value="189.95" name="choise" /> <a id='cena_viz' title="189,95 Ls" value="189.95" name="choise" class="cena"></a>
<input class="checkbox" type="checkbox" value="" name="choise" /> <a class='popup' rel="popup1"></a><a title="9,95 Ls" value="9.95" name="choise" class="cena"></a>
</div>
<div> <span id="span"></span>
User total usage: <span id="usertotal"> </span>
JavaScript
function displayVals() {
calcUsage();
var singleValues = $("#more").val();
$("#span").html("<b>more addons:</b> " +
singleValues + ' EUR');
}
var $cbs = $('input[name="choise"]');
function calcUsage() {
var total = $("#more").val();
$cbs.each(function() {
if (this.checked)
total = parseInt(total) + parseInt(this.value);
});
$("#usertotal").text(total + ' EUR');
}
$("select").change(displayVals);
displayVals();
//For checkboxes
$cbs.click(calcUsage);