我有以下几点:某处失去了变量?
var element = $(this);
var divName = element.parents("div:eq(0)").attr("name");
$.each(boxInfo,function(i,n) {
if(n.boxName == divName)
{
var newHeight = n.boxHeight;
}
});
clicked.parents("div:eq(0)").animate({
height: newHeight + 'px'
}, 1000);
问题是 “newHeight未定义”。但如果我这样做:
var element = $(this);
var divName = element.parents("div:eq(0)").attr("name");
$.each(boxInfo,function(i,n) {
if(n.boxName == divName)
{
alert(n.boxHeight);
var newHeight = n.boxHeight;
}
});
clicked.parents("div:eq(0)").animate({
height: newHeight + 'px'
}, 1000);
它返回高度。这个变量的5行是如何定义的?
你觉得什么jQuery不会在幕后?至少用'.each',一旦找到它就可以将回路短路 – nickf 2009-10-19 10:22:48