所以这是我的jquery函数 - 它应该找到并返回以控制外部文件中div的数量作为get的回调请求。难以计算外部html文件中div的数量(获取和查找) - jquery
$(document).ready(function(){
$("#button").click(function(){
$.get('source.html', function(data){
alert("Data Loaded: " + data);
var count = ($(data).find('div').size());
console.log(count);
});
console.log ($("body").find('div').size());
});
});
我收到来自source.html(其中包含2个div)的正确数据的警报,但count var总是以0出现?任何想法请你美妙的人?
HTML这里source.html:
SourceYou got loaded xxxx.
You got loaded again xxxx.
2013-04-16
KolKurtz
+1
已被弃用,因此请使用.length来查找div的数量。 http://api.jquery.com/size/ –
+0
'.size()'被描述为1.8,使用'.length'代替http://api.jquery.com/size/ –
+0
未捕获的TypeError:属性的长度'对象[object Object]不是函数 –