有人能告诉我为什么在第一个alert(items.index($(this))) = 1
和第二个alert(items.index($(this))) = -1
。这个值在另一个函数中如何改变?功能中丢失变量
$(function() {
var items = $('#v-nav>ul>li').each(function() {
$(this).click(function() {
//remove previous class and add it to clicked tab
items.removeClass('current');
$(this).addClass('current');
alert(items.index($(this)));
$('#v-nav>div.tab-content').fadeOut("slow", function() {
alert(items.index($(this)));
$('#v-nav>div.tab-content').eq(items.index($(this))).fadeIn("slow");
});
// window.location.hash = $(this).attr('tab');
});
});
就目前来看,我没有在问题中看到一个'return'语句。你有别的东西要透露给我们吗? – 2012-11-21 20:06:14
它会出现你的items变量不会填充,直到你的每个函数完成后。尽管我没有看到代码就看不出来。 –
我已经重新说明了这个问题。这可能会使我看到的行为更加清晰。 – everreadyeddy