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

Nat*_*tim 5 javascript jquery internet-explorer

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

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

它接缝表示它无法识别该initQuiz()功能.

你知道我怎么解决这个问题吗?

Dav*_*und 10

  • Internet Explorer不接受尾随逗号:

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

    $('title').html(QUIZ_TITLE[lang]);
    
    Run Code Online (Sandbox Code Playgroud)

    事实证明你不能在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);
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 第四个错误是您验证答案是否正确的方式.

    if($(this).attr('data-type') == 'true')
    
    Run Code Online (Sandbox Code Playgroud)

    您将data-type属性的值与字符串值进行比较"true",但是在分配值时,将其设置为布尔值true:

    $('#r'+(i+1)+'input').attr('data-type', r.bonne);
    
    Run Code Online (Sandbox Code Playgroud)

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

    $('#r'+(i+1)+'input').attr('data-type', r.bonne.toString());
    
    Run Code Online (Sandbox Code Playgroud)