我不太確定這裏發生了什麼事情,並且覺得我可能會錯過可能非常明顯的事情,但是我有一個如果其他語句被調用。如果有人能夠闡明這一點,這將是偉大的。下面的代碼使用asual,應該檢測div $('#' + $.address.hash()
是否已經加載。然而,如果和其他事件都按順序被解僱了。事實上else語句閃光兩次......Javascript/jQuery,if和else語句都正在執行
$('#lmit_back').show(400, function() {
if($('#' + $.address.hash()).length == 0) {
$('#init').load('inithandler.php', { 'address' : $.address.hash() }, function() {
$('#' + $.address.hash()).fadeIn(1000, function() {
$('#remn').load('pagehandler.php',{ 'address' : $.address.hash() });
});
});
}
else {
alert('hey');
}
});
這裏是所有的code..I不能真正找出什麼可能導致它執行兩次,除非有事情做與address.change這我不像我想要的那樣熟悉。
IF(($ .address.hash()== '')){$ .address.hash( '家');}
$('#lmit_back').click(function() {
$.address.hash('home');
});
$.address.change(function() {
if (!($.address.hash() == 'home'))
{
var exception = '.' + $('[href="#' + $.address.hash() + '"]').parent().attr('class');
$('#left_menu_bar li:not(' + exception + ')').hide(300,function() {
$(exception).show(function() {
$('#left_menu_bar').animate({ width:'100%'},400, function() {
$('#lmit_back').show(400, function() {
if ($('#' + $.address.hash()).length === 0)
{
$('#init').load('inithandler.php', { 'address' : $.address.hash() } , function() {
$('#' + $.address.hash()).fadeIn(1000, function() {
$('#remn').load('pagehandler.php',{ 'address' : $.address.hash() });
});
});
}
else
{
alert('nigs');
}
});
});
});
});
}
else
{
$('#left_menu_bar').animate({ width:'251px'}, function() {
$('#left_menu_bar li').show(function() {
$('#lmit_back').hide();
});
});
$('#left_menu_bar').css('width','251px');
}
});
嘗試用'==='替換'=='並檢查? –
將您的代碼放在http://jsfiddle.net/上,可以幫助人們極大地回答您的問題。 – valentinas
我懷疑你正在執行代碼不止一次。 –