我有一个不仅适用于 IE 的代码。在其他浏览器上一切正常,IE中发生的错误是这样的
Line: 11
Error: Function expected
这是小提琴,你可以随意复制粘贴,我真的不知道做什么。我不知道为什么它根本不起作用 http://jsfiddle.net/laupkram/TDWd6/
代码:
<form name="formx">
<input type="text" name="txtMultiplier">
<input type="button" value="LOOP!" onClick="loop()">
</form>
<script>
function loop(){
var mynumbers = [0,1,2,3,4,5,6,7,8,9,10];
var num = parseInt(document.formx.txtMultiplier.value);
document.write("Simulating For Loop<br>");
for(var i = 0; i < mynumbers.length; i++){
var prod = num * mynumbers[i];
document.write(mynumbers[i].toString() + " x " + num.toString() + "=" + (prod).toString() + "<br>");
}
document.write("<br>");
document.write("Simulating Do While<br>");
var i = 0;
do{
var prod = num * mynumbers[i];
document.write(mynumbers[i].toString() + " x " + num.toString() + "=" + (prod).toString() + "<br>");
i++;
}while(i < mynumbers.length);
document.write("<br>");
document.write("Simulating While<br>");
var i = 0;
while(i < mynumbers.length){
var prod = num * mynumbers[i];
document.write(mynumbers[i].toString() + " x " + num.toString() + "=" + (prod).toString() + "<br>");
i++;
}
}
</script>