我正在尝试使用输入范围滑块复习中心。它们的范围从1到10,每个sldier一侧显示一个数字,然后是/ 10。 JavaScript函数用于将滑块侧面的数字更改为正确的数字。这工作完美。HTML和JavaScript中的平均分数复习系统
问题出现在平均分数函数findaverage()中。当您调整一个滑块时,显示的值(第一个[tr]中的[span id =“averageScore”])的范围从正确的值到随机值,如233.5,这是不可能的,因为它超出了10。第二和第三滑块被调整。
我很想看到的一些想法这是为什么,并且遗憾的缩进。 干杯。
Design | 0 | /10 | Total Score: 0 |
function showValue1(newValue) {
document.getElementById("Design").innerHTML = newValue;
findaverage();
}
Functionality 0/10function showValue2(newValue) {
document.getElementById("Functionality").innerHTML = newValue;
findaverage();
}
Ease of Use 0/10function showValue3(newValue) {
document.getElementById("Ease of Use").innerHTML = newValue;
findaverage();
}
function findaverage() {
var total = 0;
var average = 0;
total += document.getElementById("Design").innerHTML;
total += document.getElementById("Functionality").innerHTML;
total += document.getElementById("Ease of Use").innerHTML;
average = total/3;
var rounded = Math.round(average * 2)/2;
document.getElementById("averageScore").innerHTML = rounded;
}
+0
@Scadoodles下面的答案会让你回到正确的路径,但是如果你想使用getElementById检索它们,你应该给你的输入一个合适的ID属性 –
2013-04-04 05:35:25