如何多次使用int变量(HTML)?

时间:2018-09-23 23:47:37

标签: javascript html html5 html-table

我的程序用于计算学生所获得的学分,以及是否属于“大学入学”(UE)学分。

一旦学生输入了五个科目的学分,我想计算学分的总数以及UE学分的总数,但是不能为每个标准多次使用分配的数量。

<script type="text/javascript">
    function dog(curetn){
        var txtJscredit = document.getElementById("txtcredit");
        var txtJscredit2 = document.getElementById("txtcredit2");
        var txtJscredit3 = document.getElementById("txtcredit3");
        var txtJscredit4 = document.getElementById("txtcredit4");
        var txtJscredit5 = document.getElementById("txtcredit5");
        var txtJscredit9 = document.getElementById("txtcredit9");
        if (curetn.includes("credit5")){
            txtcredit9.value = ((parseInt(txtJscredit.value)) + (parseInt(txtJscredit2.value)) + (parseInt(txtJscredit3.value))+ (parseInt(txtJscredit4.value))+ (parseInt(txtJscredit5.value)));
        }
        function myfuntionUE() {
            var checkBox = document.getElementById("Uni");
            var txtJscreditUE = document.getElementById("txtcredit");
            txtcreditUE.value = ((parseInt(txtJscreditUE.value))
        }
    }
</script>

3 个答案:

答案 0 :(得分:0)

<script type="text/javascript">
var txtJscredit = parseInt(document.getElementById("txtcredit"));
var txtJscredit2 = parseInt(document.getElementById("txtcredit2"));
var txtJscredit3 = parseInt(document.getElementById("txtcredit3"));
var txtJscredit4 = parseInt(document.getElementById("txtcredit4"));
var txtJscredit5 = parseInt(document.getElementById("txtcredit5"));
var txtJscredit9 = parseInt(document.getElementById("txtcredit9"));
    function dog(curetn){
if (curetn.includes("credit5")){
    txtcredit9.value = (txtJscredit.value) + (parseInt(txtJscredit2.value)) + (parseInt(txtJscredit3.value))+ (parseInt(txtJscredit4.value))+ (parseInt(txtJscredit5.value)));
}

答案 1 :(得分:0)

尝试一下。

<script type="text/javascript">
var txtJscredit;
var txtJscredit2;
var txtJscredit3;
var txtJscredit4;
var txtJscredit5;
var txtJscredit9;
    function dog(curetn){
txtJscredit = parseInt(document.getElementById("txtcredit"));
txtJscredit2 = parseInt(document.getElementById("txtcredit2"));
txtJscredit3 = parseInt(document.getElementById("txtcredit3"));
txtJscredit4 = parseInt(document.getElementById("txtcredit4"));
txtJscredit5 = parseInt(document.getElementById("txtcredit5"));
txtJscredit9 = parseInt(document.getElementById("txtcredit9"));
}

答案 2 :(得分:-2)

您可以使用类似的内容:

var txtJscredit = parseInt(document.getElementById("txtcredit"));

该变量带有一个int值。

但请注意以下情况: https://dorey.github.io/JavaScript-Equality-Table/