日期:2014-05-16 浏览次数:20458 次
$.post("http://10.200.1.22:8983/solr/collection1/select",{"q":query,"wt":"json","indent":true,"rows":10},function(data){ var response = data.response; var docs = response.docs; for(var i = 0;i<docs.length;i++) { var url = docs[i].entry_url; var li = $('<li><a href =#">'+docs[i].source_name+'</a></li>'); $("#card1").append(li); li.click(function(){ myWindow = openWindow(); loadWindowContent(myWindow,url); }); } },'json');
li.click(function(){ myWindow = openWindow(); loadWindowContent(myWindow,url); });是并发的,相当于在新的线程中执行,url跟for循环第一行的url不一致。解决办法:
var li = $('<li data-url="'+docs[i].entry_url+'"><a href ="#">'+docs[i].source_name+'</a></li>'); $("#card1").append(li); li.click(function(){ myWindow = openWindow(); loadWindowContent(myWindow,$(this).attr('data-url')); });