我使用的是 jquery 1.6.2。我的 ie 控制台中显示的错误是意外调用方法或属性访问。 jquery.min.js,第 17 行字符 29094。
我在所有现代浏览器上进行了测试,它在控制台上运行完美,没有任何错误,但是在 ie8 上尝试时,我的 xml 文件未加载。我的 ajax 调用没问题,因为 selectXml 可以运行,但里面的代码不行(它应该不会有任何问题,因为它在其他浏览器上工作,而且我已经做了 XML 验证),已经挣扎了几个小时。我认为 ie8 不能与 jquery 正常工作。
$(document).ready(function() {
$.ajax({
type: "GET",
url: "menu.xml",
dataType:"text",
success: selectXml
});
(我的 selectXml 函数)
function selectXml (xml) {
var xmlDoc = $.parseXML(xml);
console.log(xmlDoc);
var i = 0,
j = 0,
k = 0,
l = 0,
maxCat = $(xmlDoc).find("categorie").length,
maxPage = 14,
numPlate = 0,
numSection = 2,
page = 0,
queryXml,
title,
theNo,
thePlate,
thePrice,
theSection;
//for each page divide it in 2 sections
for(i=1; i<=maxPage; i++){
if( j < maxCat){
//for each sections add the title and left, right section
//for each left right section, fill up the dishes
for(k=0; k<numSection; k++){
queryXml = $(xmlDoc).find('categorie').eq(j);
title = queryXml.find("title[lang=" + jQuery.fn.language + "]").text();
numPlate = queryXml.find('plate').length;
$('#menu'+ i).append('<section></section>');
$('section').eq(j).append('<div class="menuTitle"><h1>'+ title +'</h1><div class="ribbon"></div></div><div class="menuLeft"><ul></ul></div><div class="menuRight"><ul></ul></div>');
theSection = $('section').eq(j);
for(l=0; l<numPlate; l++){
if(l< (numPlate/2)){
theNo = queryXml.find('plate').eq(l).find('number').text();
thePrice = queryXml.find('plate').eq(l).find('price').text();
thePlate = queryXml.find('plate').eq(l).find('description[lang='+jQuery.fn.language+']').text();
//console.log(thePlate);
$('section').eq(j).find('.menuLeft ul').append('<li><span class="itemNumber">' + theNo +'</span><span class="itemName">'+ thePlate+'</span> <span class="itemPrice">'+ thePrice+'</span></li>');
}
else {
theNo = queryXml.find('plate').eq(l).find('number').text();
thePrice = queryXml.find('plate').eq(l).find('price').text();
thePlate = queryXml.find('plate').eq(l).find('description[lang='+jQuery.fn.language+']').text();
$('section').eq(j).find('.menuRight ul').append('<li><span class="itemNumber">' + theNo +'</span><span class="itemName">'+ thePlate+'</span> <span class="itemPrice">'+ thePrice+'</span></li>');
}
};
numPlate = $(this).find('plate').length;
j++;
}
}//end if
}//end for
}
最佳答案
另一种方法是首先通过在页面中包含 Modernizr ( http://modernizr.com/ ) 等内容来让 IE8 理解 html5 元素。然后让其余部分按我们的预期运行。
关于Jquery XML ie8 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8238246/