如何计算股利

时间:2018-10-24 06:12:37

标签: javascript jquery html

<li class="wpProQuiz_answerCorrect">Cholera is not transmitted through persons but is caused by consuming contaminated water. A bacterial infection, it is common in places which don’t have proper sewage to ensure clean water. Cholera can lead to diarrhoea, toxins within body and dehydration.</li>

<li class="wpProQuiz_answerIncorrect">Worldwide, large companies are now following the example of Tuscany and medieval Britain in providing complex integrated solutions. Professor Williamson who wrote a paper on Tuscany agrees that this gives companies an advantage not provided by any other method of production.</li>

我正在做一个小型测验项目,我正在计算分数,具体取决于调用Quiz_answerCorrect和Quiz_answerIncorrect类的次数,因此,如果div类“ Quiz_answerCorrect”显示为答案正确且分数为1我也在通过脚本计算“ Quiz_answerIncorrect”。但是我面临的问题是,如果调用“ Quiz_answerIncorrect”会从总分中减去-1,所以我不知道如何将这两个<div>相减。谢谢,这是我的代码:

$(document).ready(function(){
    $("h4").click(function(){
        alert( $("#question_tab_706_answer li.wpProQuiz_answerCorrect").length );
    });
});

$(document).ready(function(){
    $("h3").click(function(){
        alert( $(".ui-tabs-panel li.wpProQuiz_answerIncorrect").length );
    });
});

2 个答案:

答案 0 :(得分:0)

$(document).ready(function(){
    $("h4").click(function(){
            var corr_ans = $("#question_tab_706_answer li.wpProQuiz_answerCorrect").length ;
    var wrg_ans = $(".ui-tabs-panel li.wpProQuiz_answerIncorrect").length;

    var mark = corr_ans - wrg_ans;
    if(mark < 0){
        mark = 0;
    }

    });
});

答案 1 :(得分:0)

通过获取正确和不正确答案的总和来计算项目总数。然后只需 correctAnswers / totalItems

$(document).ready(function(){

  var correct = $(".wpProQuiz_answerCorrect").length;
  var incorrect = $(".wpProQuiz_answerIncorrect").length;

  var totalItems = correct+incorrect;
  var totalScore = correct+"/"+totalItems;
  alert("Score is: "+totalScore);
});