[英]Why my JQuery doesn't load on IE?
I did this javascript quiz : http://utbm.trunat.fr/CIP/quiz/ 我做了这个javascript测验: http : //utbm.trunat.fr/CIP/quiz/
It works on normal browser but doesn't even load with Internet Explorer. 它适用于普通浏览器,但甚至不能加载Internet Explorer。
It seams that it doesn't recognize the initQuiz()
function. 它接缝不能识别
initQuiz()
函数。
Do you have any idea of how I can fix this ? 你知道我怎么解决这个问题吗?
Internet Explorer doesn't accept the trailing comma: Internet Explorer不接受尾随逗号:
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 . 事实证明你不能在IE中设置标题 。 Use
document.title = QUIZ_TITLE[lang]
instead. 请改用
document.title = QUIZ_TITLE[lang]
。
A third error is that you're introducing a new variable, question
without the var
keyword, which is an error in IE. 第三个错误是,你推出一个新的变量,
question
没有var
关键字,这是在IE错误。 You're doing it again, later on, in response
. 你以后再做一遍,作为
response
。 Update your loadXML
as such: 像这样更新你的
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); }
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
: 您将
data-type
属性的值与字符串值"true"
,但是在分配值时,将其设置为布尔值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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.