为什么这不起作用?类似的代码在这里工作:http ://www.ralphphillips.com/youtube/stick-figure/stick-figure2.html
但这行不通。我的html代码正确。ID 已设置,但每个 ID 不同。它甚至没有给出 0 的输出来表示总计为 0。没有值显示。
<!-----SAMPLE INPUT ---->
<input type="radio" autocomplete="off" id="pack11049" name="radio-73" value="1"
onkeyup="updateTotal()">
<script language="javascript">
function updateTotal() {
var optionsPrice = 0;
var accompPrice = 0;
function checkOptions() {
if (document.getElementById('pack11049').checked) {
optionsPrice += 1049;
}
if (document.getElementById('pack21199').checked) {
optionsPrice += 1199;
}
if (document.getElementById('pack31199').checked) {
optionsPrice += 1199;
}
if (document.getElementById('pack41299').checked) {
optionsPrice += 1299;
}
if (document.getElementById('pack61499').checked) {
optionsPrice += 1499;
}
if (document.getElementById('pack71549').checked) {
optionsPrice += 1549;
}
if (document.getElementById('pack81699').checked) {
optionsPrice += 1699;
}
if (document.getElementById('pack91799').checked) {
optionsPrice += 1799;
}
if (document.getElementById('pack101999').checked) {
optionsPrice += 1999;
}
if (document.getElementById('pack112499').checked) {
optionsPrice += 2499;
}
if (document.getElementById('pack122549').checked) {
optionsPrice += 2549;
}
} // end of checking for Package
function checkAccomp() {
if (document.getElementById('howmany').value == '1') {
accompPrice += 129;
}
if (document.getElementById('howmany').value == '2') {
accompPrice += 258;
}
if (document.getElementById('howmany').value == '3') {
accompPrice += 1057;
}
if (document.getElementById('howmany').value == '4') {
accompPrice += 1856;
}
} // end of check accomp function
checkPackage();
checkAccomp();
var totalPrice = optionsPrice + accompPrice;
document.getElementById('optionsPrice').innerHTML = "$ " + optionsPrice;
document.getElementById('accompPrice').innerHTML = "$ " + accompPrice;
document.getElementById('totalPrice').innerHTML = "$ " + totalPrice;
} // end of my main update total function
</script>