2013-01-10 111 views
0

在我的網頁我用Click事件tab.But代碼不爲我工作下拉。 但是,如果使用click事件的懸停,而不是它的工作原理well.But我需要使用點擊我的網頁代碼:Jquery的單擊事件不工作

$(document).ready(function(){ 
       var dropDownSpeed = 200; 
       var dropUpSpeed = 200; 
       var menuHeight = '240px'; 
       var tabs = $("#tabs"); 
       var tabPanesContainer = $("ul#tabPanes"); 
       var tabPanesAll = tabPanesContainer.find("li").css("position", "absolute"); 

       $(".slide").click(function() { 

        var thisMenuItem = $(this); 

        /*get the offset of this item in respect to the page*/ 
        var thisMargin = thisMenuItem.offset().center; 

        /*get the offset of the navigation bar in respect to the page*/ 
        var tabsOffset = tabs.offset().center; 
        var thisIndex = thisMenuItem.index(); 

        thisMargin = Math.floor(thisMargin - tabsOffset); 


        var thisOffset = thisMargin - 52; 

        /* handle IE margin difference*/ 
        if($.browser.msie) 
        { 
         thisOffset = thisMargin - 15; 
        } 


        tabPanesContainer.css('margin-left', thisOffset); 

        tabPanesContainer.stop().animate({ 
         height: menuHeight 
        }, dropDownSpeed); 



        tabMenuLinks.removeClass('activeTab'); 
        thisMenuItem.addClass('activeTab'); 


        var thisHash = thisMenuItem.find("a").attr('href'); 
        var tabClicked = tabPanesAll.filter(thisHash); 


        tabClicked.appendTo(tabPanesContainer).show(); 



        return false; 


       }, function() { 

        $(this).stop(); 

       }); 
       }); 
      }); 

請幫我解決這個問題謝謝...

回答

2

你有wrong syntax for the click event ..

它發生在只有一個功能處理,而不是兩成你寫

$(".slide").click(function() { 

    // Click event code 
}, function() { 
       $(this).stop(); 

}); 

件作品懸停事件,因爲它可以採取兩種處理函數..

Click事件的工作你的簽名必須是

$(".slide").click(function() { 

     // Click event code 
}); 

// Remove the other function 
+0

我刪除了另一個功能,但它不工作 – ajay

+0

您可以創建一個工作小提琴示出此問題 –

+0

我需要的是,如果用戶點擊「Forgot Password」鏈接,然後一個下拉選項卡必須出現在鏈接下方 – ajay

0

從技術上講,你不應該通過二次回調,發生了什麼是你的:

$(this).stop(); 

在所有其他代碼之前發射。 javascript忽略了你指定的第一個回調函數,因爲.click只能在回調方法上接受。我很好奇什麼是你的.stop()甚至被用於?我並不完全確定,但我並不認爲你完全需要。其他

一個忠告是使用。對()方法,而不是點擊。的。點擊()方法已經被廢棄了的所以不是你必須使用類似這樣的內容:

$(".slide").on('click', function() { 
    // Click event code 
}); 

什麼你使用。點擊做()僅僅是撥打電話到這個。對()反正加使用。對()是更可擴展的意義,現在你可以綁定多個事件監聽因此,例如,你可以這樣做:

$(".slide").on('click, mouseover, mouseenter', function() { 
    // Click event code 
}); 
+0

我刪除了$(this).stop;如果我使用上述方法,問題仍然存在。 – ajay