基本上我使用html5滑块来更改值。但几次改变价值后,整个网页都崩溃了。在更改滑块的值时,每次调用一个函数。我是新手。请有人帮帮我吗?
滑块代码如下:
<input type="range" id="B1" name="B1" value="0" min="-2" max="2" step="0.1" onchange="JavaScript:main();" oninput="B1val.value = B1.value" />
我使用了许多滑块,如上图所示,并借助此滑块的输入绘制图形。 main()函数放在标签之间,写在下面以供参考::
function main() {
// lots more features are available, this is just a "hello world"
// program.
var b0 = document.getElementById("B0").value;
var b1 = document.getElementById("B1").value;
var b2 = document.getElementById("B2").value;
var b3 = document.getElementById("B3").value;
var b4 = document.getElementById("B4").value;
var b5 = document.getElementById("B5").value;
var b6 = document.getElementById("B6").value;
var b7 = document.getElementById("B7").value;
var b8 = document.getElementById("B8").value;
var b9 = document.getElementById("B9").value;
var b10 = document.getElementById("B10").value;
var b11 = document.getElementById("B11").value;
var b12 = document.getElementById("B12").value;
var d = document.getElementById("funct").value;
var f = document.getElementById("terms").value;
var fun = document.getElementById("Target").value;;
var b = 1;
var e = 0;
var g = 1;
var h = 1;
var j = 0;
if(d == "sin" && f == "even"){
document.getElementById("equat").innerHTML = "B2sin(2t)+B4sin(4t)+B6sin(6t)+B8sin(8t)+B10sin(10t)+....";
document.getElementById("B0").disabled = true;
document.getElementById("B1").disabled = true;
document.getElementById("B3").disabled = true;
document.getElementById("B5").disabled = true;
document.getElementById("B7").disabled = true;
document.getElementById("B9").disabled = true;
document.getElementById("B11").disabled = true;
}
if(d == "sin" && f == "odd"){
document.getElementById("equat").innerHTML = "B1sin(t)+B3sin(3t)+B5sin(5t)+B7sin(7t)+B9sin(9t)+....";
document.getElementById("B0").disabled = true;
document.getElementById("B2").disabled = true;
document.getElementById("B4").disabled = true;
document.getElementById("B6").disabled = true;
document.getElementById("B8").disabled = true;
document.getElementById("B10").disabled = true;
document.getElementById("B12").disabled = true;
}
if(d == "sin" && f == "evenodd"){
document.getElementById("equat").innerHTML = "B1sin(t)+B2sin(2t))+B3sin(3t)+B4sin(4t)+B5sin(5t)+...";}
if(d == "cos" && f == "even"){
document.getElementById("equat").innerHTML = " (0.5)B0+B2cos(2t)+B4cos(4t)+B6cos(6t)+B8cos(8t)+...";
document.getElementById("B1").disabled = true;
document.getElementById("B3").disabled = true;
document.getElementById("B7").disabled = true;
document.getElementById("B9").disabled = true;
document.getElementById("B11").disabled = true;
}
if(d == "cos" && f == "odd"){
document.getElementById("equat").innerHTML = " B1cos(t)+B3cos(3t)+B5cos(5t)+B7cos(7t)+B9cos(9t)+...";
document.getElementById("B0").disabled = true;
document.getElementById("B2").disabled = true;
document.getElementById("B4").disabled = true;
document.getElementById("B6").disabled = true;
document.getElementById("B8").disabled = true;
document.getElementById("B10").disabled = true;
document.getElementById("B12").disabled = true;
}
if(d == "cos" && f == "evenodd"){
document.getElementById("equat").innerHTML = " (0.5)B0+B1cos(t)+B2cos(2t)+B3cos(3t)+B4cos(4t)+...";}
if(d == "cos" && f == "evenodd") {j = 1;}
else if(d == "cos" && f == "even") {j = 1;}
else {j = 0;}
if(d == "sin") {b = "sin"; d = 1;}
if(d == "cos") {b = "cos"; d = 1;}
if(d == "sincos") {d = 0; e = 1;}
if(f == "even") {g = 0; h = 1;}
if(f == "odd") {g = 1; h = 0;}
myPlot = new Waveplot(document.getElementById('myPlot'));
myPlot.addPlot(j+"(0.5)*"+b0+"+"+d+"("+b1+"*"+g+"*"+b+"(0.5*3.14159*x)"+"+"+b2+"*"+h+"*"+b+"(2*3.14159*0.5*x)"+"+"+b3+"*"+g+"*"+b+"(3*3.14159*0.5*x)"+"+"+b4+"*"+h+"*"+b+"(4*3.14159*0.5*x)"+"+"+b5+"*"+g+"*"+b+"(5*3.14159*0.5*x)"+"+"+b6+"*"+h+"*"+b+"(6*3.14159*0.5*x)"+"+"+b7+"*"+g+"*"+b+"(7*3.14159*0.5*x)"+"+"+b8+"*"+h+"*"+b+"(8*3.14159*0.5*x)"+"+"+b9+"*"+g+"*"+b+"(9*3.14159*0.5*x)"+"+"+b10+"*"+h+"*"+b+"(10*3.14159*0.5*x)"+"+"+b11+"*"+g+"*"+b+"(11*3.14159*0.5*x)"+"+"+b12+"*"+h+"*"+b+"(12*3.14159*0.5*x)"+")",WAVEPLOT_TYPE_FUNCTION);
myPlot.addPlot(fun+"(x)",WAVEPLOT_TYPE_FUNCTION);
myPlot.reDraw();
}