的最大值是在你的情況下,100所以你沒有找到它選定值嘗試每個time.As:
var temp = document.getElementById("ddlist1");
var selectedValue = temp.options[temp.selectedIndex].value;
爲了得到最後一個值的嘗試:
var lastValue = temp.options[temp.options.length - 1].value;
或者,如果你使用jQuery的你可以試試:
var lastValue = $('#ddlist1 option:last-child').val();
已更新: 試試這個腳本
function sum() {
var f, ddlist, sval, mval,
result = 0, maxtotal = 0, percent;
// try 'ddlist1', 'ddlist2', .. and so on
f = 1;
while (ddlist = document.getElementById('ddlist' + f++)) {
sval = ddlist.options[ddlist.selectedIndex].value;
mval = ddlist.options[ddlist.options.length - 1].value;
if (!isNaN(sval) && !isNaN(mval)) {
result += parseFloat(sval);
maxtotal += parseFloat(mval);
}
}
percent = (maxtotal > 0) ? result/maxtotal * 100 : 0;
document.getElementById('maxtotal').innerHTML = result + ' of ' + maxtotal;
document.getElementById('totalper').innerHTML = percent.toFixed(2) + ' %';
}
你想達到什麼目的?兩個值的總和,平均值和最大值? – arjuncc
我想獲得所選值和所選值的百分比之和,即選擇/最大值 – user3300202