计算试题总分(权重不同)

<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;
        }

 

转载于:https://www.cnblogs.com/chrdai/p/6508763.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值