爲什麼我無法獲得此功能?在點擊時設置VAR並提醒您的值
我想從菜單中獲取index(),並在hash更改時獲取alert()值。
不顯示警報。
$('#menu li a').click(function() {
var index = $(this).parent().index()+1;
});
$(window).bind('hashchange', function() { //detect hash change
var hash = window.location.hash.slice(1); //hash to string (= "myanchor")
alert(index);
});
你能告訴我我在做什麼錯嗎?
通過使用`var`,你正在使'click'功能的`index`變爲本地。 – 2011-02-15 11:30:28