0

我试图计算获得的分数并希望它显示在表格中。与在 javascript 中一样,我所做的计算如下:

<script>
                        function kira1() {
                            var myeBook = document.getElementById('eBook').value;
                            var result = document.getElementById('result1');
                            var myResult = myeBook * 3;
                            result.value = myResult;
                        }
                        function kira2() {
                            var mybukuTeks = document.getElementById('bukuTeks').value;
                            var result = document.getElementById('result2');
                            var myResult = mybukuTeks * 3;
                            result.value = myResult;
                        }
                        function kira3() {
                            var mymodul = document.getElementById('modul').value;
                            var result = document.getElementById('result3');
                            var myResult = mymodul * 2;
                            result.value = myResult;
                        }
                        function kira4() {
                            var myjurnal = document.getElementById('jurnal').value;
                            var result = document.getElementById('result4');
                            var myResult = myjurnal * 2;
                            result.value = myResult;
                        }
                        function kira5() {
                            var myePembelajaran = document.getElementById('ePembelajaran').value;
                            var result = document.getElementById('result5');
                            var myResult = myePembelajaran * 1;
                            result.value = myResult;
                        }
                        function kira6() {
                            var myinovasi = document.getElementById('inovasi').value;
                            var result = document.getElementById('result6');
                            var myResult = myinovasi * 1;
                            result.value = myResult;
                        }
                        function kira7() {
                            var a = document.getElementById('result1').value;
                            var b = document.getElementById('result2').value;
                            var c = document.getElementById('result3').value;
                            var d = document.getElementById('result4').value;
                            var e = document.getElementById('result5').value;
                            var f = document.getElementById('result6').value;
                            var result = document.getElementById('jumlah_1A');
                            var myResult = a + b + c + d + e + f;
                            result.value = myResult;
                        }           
                    </script>

但是当我尝试运行它时,总数没有按我想要的那样显示。

这是输出: 在此处输入图像描述

总数应显示在“Jumlah Skor 1A”

4

2 回答 2

0

尝试使用:

document.getElementById('jumlah_1A').innerHTML
i.e. document.getelementbyid('idname').innerHTML

据我了解,“jumlah_1A”是一个 div,而不是一个输入框。所以使用 .innerHTML 而不是 .value

W3school 链接: http ://www.w3schools.com/jsref/prop_html_innerhtml.asp

于 2016-05-16T08:26:04.330 回答
0
var a = parseInt(document.getElementById('result1').value);
var b = parseInt(document.getElementById('result2').value);
var c = parseInt(document.getElementById('result3').value);
var d = parseInt(document.getElementById('result4').value);
var e = parseInt(document.getElementById('result5').value);
var f = parseInt(document.getElementById('result6').value);

在添加值之前将所有转换为整数。如果 jumlah_1A 元素不是文本框,则执行

result.innerHTML = myResult;
于 2016-05-16T08:37:44.427 回答