为什么我的JQuery在IE上无法加载?

5

我做了这个JavaScript测验:http://utbm.trunat.fr/CIP/quiz/

在普通浏览器上可以运行,但在Internet Explorer中甚至无法加载。

看起来它无法识别initQuiz()函数。

你有任何想法如何解决这个问题吗?


消息:意外调用方法或属性访问。 行:113 字符:460 代码:0 URI:http://utbm.trunat.fr/CIP/quiz/js/jquery-1.4.4.min.js消息:对象不支持此属性或方法 行:110 字符:6 代码:0 URI:http://utbm.trunat.fr/CIP/quiz/js/start-quiz.js - simon
1
我喜欢浏览器分为两类:普通浏览器和IE。 - David Tang
1个回答

10
  • Internet Explorer doesn't accept the trailing comma:

    question = {'texte': $(this).attr("texte"),
        'sound': $(this).attr("sound"),}
    
  • Apparently, another error comes from this line:

    $('title').html(QUIZ_TITLE[lang]);
    

    Turns out you can't set the title like that in IE. Use document.title = QUIZ_TITLE[lang] instead.

  • A third error is that you're introducing a new variable, question without the var keyword, which is an error in IE. You're doing it again, later on, in response. Update your loadXML as such:

    function loadXML(xml) {
       $(xml).find("question").each(function() {
        var question = {'texte': $(this).attr("texte"), 'sound': $(this).attr("sound")};
    
          reponses = [];
          $(this).find('carre').find('reponse').each(function() {
            var reponse = {'texte': $(this).text(), 'sound': $(this).attr("sound"), 'bonne': false};
            if($(this).attr('bonne') == "vrai") reponse['bonne'] = true;            
            reponses.push(reponse);
         });
    
         question['reponses'] = reponses;
         questions.push(question);
       });
       startGame(questions);
    }
    
  • A fourth error is in the way you're verifying that an answer is correct.

    if($(this).attr('data-type') == 'true')
    

    You compare the value of the data-type attribute to the string value "true", but when you assign the value, you set it to the boolean value true:

    $('#r'+(i+1)+'input').attr('data-type', r.bonne);
    

    To make sure that you're always comparing string values, for instance, you could set the value as such:

    $('#r'+(i+1)+'input').attr('data-type', r.bonne.toString());
    

当声音未定义时,是否可能是 $(this).attr('sound') 引发了错误? - Natim
那个错误出现在 loadXML(xml) 中。它阻止了 loadXML 和可能其他函数的执行。在此得到纠正之前,很难确定是否存在其他错误。 - David Hedlund
啊,有趣。我会再看一下的。 - David Hedlund
我使用 http://www.jslint.com/ 修复了其他错误,但仍然无法正常工作。 - Natim
我找到了为什么你在测验中总是得到错误答案的原因;请看我的更新答案。我不确定你在swfobject方面的意思。对我来说,带有播放和暂停按钮的小“控制面板”看起来很好。 - David Hedlund
显示剩余4条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接