HTMLが含まれていない場合は、いくつかの属性を変更する必要があります
var input = document.getElementsByTagName("input");
var total = document.getElementById("total");
for(i=0;i<input.length;i++){
input[i].onchange = function(){
if(this.checked){
total.innerHTML = parseFloat(total.innerHTML) + parseFloat(this.value);
}else{
total.innerHTML = parseFloat(total.innerHTML) - parseFloat(this.value);
}
}
}
$を忘れた
var input = document.getElementsByTagName("input");
var total = document.getElementById("total");
for(i=0;i<input.length;i++){
input[i].onchange = function(){
if(this.checked){
total.innerHTML = "$" + (parseFloat(total.innerHTML.split("$")[1]) + parseFloat(this.value));
}else{
total.innerHTML = "$" + (parseFloat(total.innerHTML.split("$")[1]) - parseFloat(this.value));
}
}
}