我正在开发异步数据库搜索工具。它目前与firefox和chrome一起使用,但与Internet Explorer(版本8)有一个巨大的呃逆。在列表中使用JQUERY不显示JSON数据的IE8
学生可以输入他们的潜在MCAT和GPA分数,然后jquery将他们放置在前25%或中50%的学校分类。基本上,这是一个神经过敏的学生的梦想(或噩梦)。
jquery循环遍历JSON数据,显示与<li>
条目中的条件匹配的每个项目。再一次,它在ff和chrome中运行良好,但在Internet Explorer中它拒绝显示列表项。但是,它会显示正确的项目数,这意味着json数据正常运行。
在通过stackoverflow搜索后,我看到了一些关于IE如何拒绝将表元素和其他一些使用jquery的innerhtml元素放入元素的解释(多彩,经常!)。
我想知道这是否是问题,虽然我发现this question类似的问题,我不能完全弄清楚如何适应我的项目(我是新来的JavaScript)。
任何帮助将是美好的。代码可以在下面找到。
-samuel
$.getJSON("schoolgrabber.php?jsoncallback=?", function(data){
//loop through the items in the array
for(var x=0; x < data.length; x++){
if(MCAT >= data[x].TopPercentileMCAT && data[x].TopPercentileMCAT!=''){
var li = $("<li>").appendTo("#schoollist");
var school= data[x].School;
//add the actual information into the li using a chain event
//the event begins by appending an <a> tag, with the name of the school inside (text(data[x].School)
//then it adds a unique id, which is the iteration number the counter is on above (x)
//then it adds the url, and adds the school variable, which allows the schools to be clicked over to the results page
//then it puts all of that inside li, as declared above (slightly backwards, but hey)
$("<a>").text(data[x].School).attr("id",x).attr("href", "results.php?school=" + school).appendTo(li);
$("#schoollist li").addClass("school");
var quantity = $(".school").length;
$('#schoolquantity').empty();
$('#schoolquantity').append(quantity);
}}
});
美丽!非常感谢你的迅速和知识丰富的回应。我一直在自学教学,并且遇到了IE的问题(加上,不知道如何正确优化,这是显而易见的),它比你可能意识到的更有帮助,让这个社区在我的指尖。 我必须编辑的唯一东西是标签在学校后面的另一个“+”,否则它的工作完美。非常感谢。 – samuel 2011-04-25 01:34:38
没问题samuel :)是的,这个网站对任何语言的新手都很有帮助(当我学习javascript的时候,它对我也有很大的帮助)。当你有他们时请继续提问! – Polaris878 2011-04-25 23:03:51