这是我在 java 脚本中的代码:
function DrawPollBars(BarVar, BarWidth) {
var newbar = new Array();
newbar = BarVar;
var newWidth = new Array();
newWidth = BarWidth;
var IncVa;
TotalVotes = sum(BarVar, BarWidth);
IncVal = parseFloat(TotalVotes / 10);
//var percent = 0.00; var count = 0;
var NewBarWidthb = new Array();
var BarNextVar = new Array();
//NewBarWidth = "NewBarWidth" + x;
NewBarWidthb[x] = 0;
//NewBarWidthb[x] = NewBarWidth;
for (var x = 1; x < BarWidth.length; x++) {
var PollBar = document.getElementById('PollBar' + x);
var PollRate = document.getElementById('PollRate' + x);
if (parseInt(parseInt(BarVar[x]) * 200 / TotalVotes) > 0) NewBarWidthb[x] = parseInt(BarVar[x]) * 200 / TotalVotes;
else if (BarVar[x] >= 0) NewBarWidthb[x] = 1;
else NewBarWidthb[x] = 0;
var pollbar = PollBar.style.width = NewBarWidthb[x] + 'px';
var pollrate = PollRate.innerHTML = parseFloat(BarVar[x]).toFixed(0) + " (" + parseFloat(parseFloat(BarVar[x]) / TotalVotes * 100).toFixed(1) + "%)";
//percent = parseFloat(parseFloat(BarWidth[x]) / TotalVotes * 100).toFixed(2) ;
// count = parseFloat(BarWidth[x]).toFixed(0);
if (BarVar != BarWidth) {
if (parseFloat(BarVar[x]) + IncVal <= parseInt(BarWidth[x])) BarNextVar[x] = parseFloat(BarVar[x]) + IncVal; else BarNextVar = BarWidth;
}
}
var ff = window.setTimeout("DrawPollBars([" + BarNextVar + "],[" + BarWidth + "]);", 90);
}
第一次单击 btn 时它可以正常工作,但第二次似乎不正确,我不知道原因