zoukankan      html  css  js  c++  java
  • 计算试题总分(权重不同)

    <table>
        <thead>
            <tr>
               <th>第一题得分</th>
               <th>第二题得分</th>
               <th>第三题得分</th>
               <th>第四题得分</th>
               <th>第五题得分</th>
               <th>总分</th>
            </tr>
        </thead>
        <tbody>
            <tr>
               <td><input class="score" num="0" type="text"></td>
               <td><input class="score" num="1" type="text"></td>
               <td><input class="score" num="2" type="text"></td>
               <td><input class="score" num="3" type="text"></td>
               <td><input class="score" num="4" type="text"></td>
               <td><input name="score" type="text"></td>
             </tr>
         </tbody>
    </table>
    
     //计算五题的总分,每题满分十分,共5道题,共50分,
            function sum() {
                var total = 0;
                $('.score').each(function () {
                    var num = $(this).attr('num');
                    var sum = $(".degree:eq("+num+")").attr('sum');     // 五道题加起来的难度系数
                    var degree = $(".degree:eq("+num+")").attr('degree');   // 本题的难度系数
                    var weight = degree/sum;        // 权重
                    var score = $(this).val();
                    var realScore = (score/10)*(50*weight);    // (每道题的评分/该题的总分)*(该题占所有题目的权重)*总分
                    realScore = realScore.toFixed(2);
                    total += parseFloat(realScore);
                });
                total = total.toFixed(2);   //toFixed() 方法可把 Number 四舍五入为指定小数位数的数字。
                return total;
            }
  • 相关阅读:
    CCCC练习即感
    1003 我能通过
    录制开讲啦杂感
    OOP第三次上机
    关于C++随机函数
    蓝桥杯杂感。
    CF502C The Phone Number
    It's a secret
    2017-06-22
    2017-05-12
  • 原文地址:https://www.cnblogs.com/chrdai/p/6508763.html
Copyright © 2011-2022 走看看