Jquery指望多个页面

时间:2012-03-25 23:35:45

标签: jquery

我正在尝试制作多个定格,以便跟踪每个页面上的每个测验。

所以,到目前为止,我只有一个计数器,无法跟踪测验被回答的页面。

我的所有测验都在ID tag =“jquiz”中,所以我只需要使用一个样式表。我如何为我的代码实现多个计数器

编辑:更新代码

 $(".jquiz li ul li").click(function(){

    if (!($(this).parent("ul").hasClass("answered"))) {

        // removes unanswered class and adds answered class so they cannot change answer
        $(this).parent("ul").addClass("answered");

        // runs if they clicked the correct answer
        if ($(this).hasClass("correct")) {
            //adds one to quiz total correct tally
            count++;
             }


             //score check
            if ($('ul.answered').length == 3) {
            $('#page1mark').fadeIn('slow');
            $('#page1total').html('You got a '+count+' out of '+3+' on the page 1quiz.');
        }

        if ($('ul.answered').length == 6) {
            $('#page2mark').fadeIn('slow');
            $('#page2total').html('You got a '+count+' out of '+3+' on the page 2 quiz.');
        }

        if ($('ul.answered').length == howmanyquestions) {
            $('#jquizremarks').fadeIn('slow');
            $('#jquiztotal').html('You got a '+count+' out of '+howmanyquestions+' on the total quiz.');
        }
    }
}};


   //---------The html
        <!-- page1--->
    <ol class="jquiz"> //how do i add IDs to each class in a page?
         <li>
            <p>Cake is yum</p>
                 <ul>
                 <li class="correct">True</li>
                <li>False</li>
    </ul>
    </li>
  </ol>

1 个答案:

答案 0 :(得分:1)

您不能拥有两个具有相同ID的html元素。因此,要做你想要的,html元素应该是具有不同ID的相同类,所以:

  1. 替换id="jquiz"
  2. ol元素中的class="jquiz"
  3. 更改用于计算有多少问题的jquery选择器;从$("#jquiz > li")$(".jquiz > li")
  4. 最后更改设置点击处理程序的jquery选择器;从$("#jquiz li ul li")$(".jquiz li ul li")
相关问题