-4

我已经对此进行了一段时间的错误检查,但我仍然无法弄清楚出了什么问题。它应该记我的成绩,并吐出我的零用钱。它以前可以工作,但是 JSfiddle 把它搞砸了,现在它遇到了其他问题。谁能告诉我出了什么问题?代码:

<head>
<script>
alert('loaded');
function Runme() {
    alert("running");
    document.forms["form"].Runme();
    var Mathematics = document.personal.Mathematics;
    var OMathematics = document.personal.OMathematics;
    var Sci = document.personal.Sci;
    var OSci = document.personal.OSci;
    var ELA = document.personal.ELA;
    var OELA = document.personal.OELA;
    var SS = document.personal.SS;
    var OSS = document.personal.OSS;
    var Elec1 = document.personal.Elec1;
    var OElec1 = document.personal.OElec1;
    var Elec2 = document.personal.Elec2;
    var OElec2 = document.personal.OElec2;
    var Elec3 = document.personal.Elec3;
    var OElec3 = document.personal.OElec3;
    var Elem1 = document.personal.Elec1;
    var OElem1 = document.personal.OElec1;
    var Elem2 = document.personal.Elec2;
    var OElem2 = document.personal.OElec2;
    var Elem3 = document.personal.Elec3;
    var OElem3 = document.personal.OElec3;
    var Owed = 0;
    var Calc = function(n, o) {
        if (n >= 90) {
            Owed = Owed + 1;
            if (n >= 95) {
                Owed = Owed + 1;
            }
        }
        else if (owed >= 80) {
            Owed = Owed + 0.5;
        }
        if (n > o) {
            Owed = Owed + 0.5;
        }
        if (n < o) {
            if (n > 95) {
                Owed = Owed - 0.25;
            }
        }
    };
    Calc(Mathematics, OMathematics);
    Calc(Sci, OSci);
    Calc(ELA, OELA);
    Calc(SS, OSS);
    Calc(Elec1, Elec1);
    Calc(Elec2, Elec2);
    Calc(Elec3, Elec3);
    Calc(Elem1, Elem1);
    Calc(Elem2, Elem2);
    Calc(Elem3, Elem3);
    alert(Owed);
};
</script>
</head>
<body>
<center>
<h1>Grade Calculator</h1>
<!--form name="form" action="grades.pl" onsubmit="return checkscript()"-->
<h5>Math</h5><input type=text size=20 name=Mathematics>
<h5>Old Math</h5><input type=text size=20 name=OMathematics>
<h5>Science</h5><input type=text size=20 name=Sci>
<h5>Old Science</h5><input type=text size=20 name=OSci>
<h5>English</h5><input type=text size=20 name=ELA>
<h5>Old English</h5><input type=text size=20 name=OELA>
<h5>Social Studies</h5><input type=text size=20 name=SS>
<h5>Old Social Studies</h5><input type=text size=20 name=OSS>
<h5>Elective One</h5><input type=text size=20 name=Elec1>
<h5>Old Elective One</h5><input type=text size=20 name=OElec1>
<h5>Elective Two</h5><input type=text size=20 name=Elec2>
<h5>Old Elective Two</h5><input type=text size=20 name=OElec2>
<h5>Elective Three</h5><input type=text size=20 name=Elec3>
<h5>Old Elective Three</h5><input type=text size=20 name=OElec3>
<h5>Elem One</h5><input type=text size=20 name=Elec3>
<h5>Old Elem One</h5><input type=text size=20 name=OElec3>
<h5>Elem Two</h5><input type=text size=20 name=Elec3>
<h5>Old Elem Two</h5><input type=text size=20 name=OElec3>
<h5>Elem Three</h5><input type=text size=20 name=Elec3>
<h5>Old Elem Three</h5><input type=text size=20 name=OElec3>
</form>
<br/>
<input type="button" value="Submit and Calculate" onClick="Runme()"/>
</center>

</body>
4

2 回答 2

1

嗯,首先你需要一个<form>元素,它显然已经被注释掉了。

其他注意事项:
确保始终使用相同的案例。“欠”!=“欠”。
onClick 应该是“onclick”,尽管大多数浏览器都允许它工作。

<head>
<script>
    //alert('loaded');
function Runme() {
    //    alert("running");
    //document.forms["personal"].Runme();
    var Mathematics = document.personal.Mathematics;
    var OMathematics = document.personal.OMathematics;
    var Sci = document.personal.Sci;
    var OSci = document.personal.OSci;
    var ELA = document.personal.ELA;
    var OELA = document.personal.OELA;
    var SS = document.personal.SS;
    var OSS = document.personal.OSS;
    var Elec1 = document.personal.Elec1;
    var OElec1 = document.personal.OElec1;
    var Elec2 = document.personal.Elec2;
    var OElec2 = document.personal.OElec2;
    var Elec3 = document.personal.Elec3;
    var OElec3 = document.personal.OElec3;
    var Elem1 = document.personal.Elec1;
    var OElem1 = document.personal.OElec1;
    var Elem2 = document.personal.Elec2;
    var OElem2 = document.personal.OElec2;
    var Elem3 = document.personal.Elec3;
    var OElem3 = document.personal.OElec3;
    var Owed = 0;
    var Calc = function(n, o) {
        if (n >= 90) {
            Owed = Owed + 1;
            if (n >= 95) {
                Owed = Owed + 1;
            }
        }
        else if (Owed >= 80) {
            Owed = Owed + 0.5;
        }
        if (n > o) {
            Owed = Owed + 0.5;
        }
        if (n < o) {
            if (n > 95) {
                Owed = Owed - 0.25;
            }
        }
    };
    Calc(Mathematics, OMathematics);
    Calc(Sci, OSci);
    Calc(ELA, OELA);
    Calc(SS, OSS);
    Calc(Elec1, Elec1);
    Calc(Elec2, Elec2);
    Calc(Elec3, Elec3);
    Calc(Elem1, Elem1);
    Calc(Elem2, Elem2);
    Calc(Elem3, Elem3);
    alert(Owed);
};
</script>
</head>
<body>
<center>
<h1>Grade Calculator</h1>
<form name="personal" action="grades.pl">
<h5>Math</h5><input type=text size=20 name=Mathematics>
<h5>Old Math</h5><input type=text size=20 name=OMathematics>
<h5>Science</h5><input type=text size=20 name=Sci>
<h5>Old Science</h5><input type=text size=20 name=OSci>
<h5>English</h5><input type=text size=20 name=ELA>
<h5>Old English</h5><input type=text size=20 name=OELA>
<h5>Social Studies</h5><input type=text size=20 name=SS>
<h5>Old Social Studies</h5><input type=text size=20 name=OSS>
<h5>Elective One</h5><input type=text size=20 name=Elec1>
<h5>Old Elective One</h5><input type=text size=20 name=OElec1>
<h5>Elective Two</h5><input type=text size=20 name=Elec2>
<h5>Old Elective Two</h5><input type=text size=20 name=OElec2>
<h5>Elective Three</h5><input type=text size=20 name=Elec3>
<h5>Old Elective Three</h5><input type=text size=20 name=OElec3>
<h5>Elem One</h5><input type=text size=20 name=Elec3>
<h5>Old Elem One</h5><input type=text size=20 name=OElec3>
<h5>Elem Two</h5><input type=text size=20 name=Elec3>
<h5>Old Elem Two</h5><input type=text size=20 name=OElec3>
<h5>Elem Three</h5><input type=text size=20 name=Elec3>
<h5>Old Elem Three</h5><input type=text size=20 name=OElec3>
</form>
<br/>
<input type="button" value="Submit and Calculate" onclick="Runme()"/>
</center>

</body>
于 2012-09-30T22:12:32.347 回答
0
document.forms["form"].Runme();

会失败,因为没有这种形式,而且Runme无论如何它也没有方法。

document.personal...

将失败,因为没有这样的事情。

尝试摆脱对虚假表单的引用,并替换所有使用

document.personal.inputName

document.getElementsByName("inputName")[0].value
于 2012-09-30T22:12:03.243 回答