<script>
    function calculateAverage() {
        var chinese = document.getElementById("txtChinese").value;
        var math = document.getElementById("txtMath").value;
        var english = document.getElementById("txtEnglish").value;

        if (isNaN(chinese) || isNaN(math) || isNaN(english)) {
            alert("请输入数字");
            return;
        }

        var average = (parseFloat(chinese) + parseFloat(math) + parseFloat(english)) / 3;
        document.getElementById("txtAverage").value = average.toFixed(2);
    }

    document.querySelector('input[type="button"]').addEventListener("click", calculateAverage);
</script>
补充下面的JavaScript代码使其能够完成求算语文、数学、英语三科的平均分。要求能够判断输入的是否是数字而且计算结果精确到小数点后两位。html	head		titleJavaScript 实例title	head			body		学生成绩录入:		hr		form id=frmMain									语文:input type=text id=txtChinese value=85 siz

原文地址: https://www.cveoy.top/t/topic/62W 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录