工作: 最初,当测验在 index.html 中时,一切正常。我可以使用#quiz 访问测验部分,如下所示:
<div data-role="content">   
<ul data-role="listview">
    <li><a href="#quiz">Quiz Page</a></li>
    <li><a href="#page3">Page Three</a></li>
</ul>       
然后,我决定将测验作为一个独立的 html 页面。因此,我从 index.html 中剪切了用于评分和问题隐藏显示脚本的 javascript,以及测验问题并将其粘贴到 quiz.html 页面中。为了访问此测验页面,我将 index.html 中的链接修改为
<div data-role="content">   
    <ul data-role="listview">
        <li><a href="quiz.html">Quiz Page</a></li>
        <li><a href="#page3">Page Three</a></li>
    </ul>       
</div>
评分脚本如下(简化):
<script type="text/javascript"> //scoring script
function getScore(form){
  //score counting algorithm
  score = Math.round(score/AnswersAndObjects.length*100);
  form.percentage.value = score + "%";
}
</script>
问题隐藏显示脚本如下(简化):
<script type="text/javascript"> //quiz question hide-show script
        $(document).ready(function () {
            var currentQuestion=0;
            var totalQuestions=$('.questions').length;
            $questions = $('.questions');
            //show the first question
            //when users click on the "Next question button...
            $('#next').click(function(){
                $($questions.get(currentQuestion)).fadeOut(function(){ //hide the current question
                    //go to next question
                    if(currentQuestion == totalQuestions){ //if no more question
                        //do hide and show div class                                    
                    }else{
                        //else display the current question
                    }
                });
            });
         });
</script>
供您参考,每个问题都包装为
<div class="questions">Question here</div>
问题:当我从index.html 访问 quiz.html时,没有任何效果。无法计算分数并且 show() hide() 不起作用。但是,如果我直接访问 quiz.html ,一切正常。我怀疑从 index.html 访问 quiz.html 时没有加载 javascript。但是,我已经包括
$(document).ready(function () {  
在 quiz.html 中。
我可以知道我怎样才能完成这项工作吗?