为什么我的JQuery不能加载IE?

时间:2011-01-10 10:05:13

标签: javascript jquery internet-explorer

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

它适用于普通浏览器,但甚至不能使用Internet Explorer加载。

它接触到它无法识别initQuiz()功能。

你知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:10)

  • Internet Explorer不接受尾随逗号:

    question = {'texte': $(this).attr("texte"),
        'sound': $(this).attr("sound"),}
    
  • 显然,另一个错误来自这一行:

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

    结果you can't set the title like that in IE。请改用document.title = QUIZ_TITLE[lang]

  • 第三个错误是您引入了一个新变量question而没有var关键字,这在IE中是一个错误。你稍后会在response中再次这样做。请更新您的loadXML

    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);
    }
    
  • 第四个错误是您验证答案是否正确的方式。

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

    您将data-type属性的值与字符串值"true"进行比较,但是当您指定值时,将其设置为布尔值{{1} }:

    true

    例如,为确保您始终比较字符串值,您可以将值设置为:

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