2014-12-18 56 views
0

我有一個jQuery的切換按鈕,當我點擊它時,谷歌地圖顯示在下面。但我不想使用切換事件。我想在打開網站時顯示Google地圖(無切換)。我怎樣才能刪除這個事件?這是我的js代碼。我有JQuery的切換問題

__mapButton.unbind("click").on("click", __renderGoogleMap); 

this.renderGoogleMap = __renderGoogleMap; 
var __renderGoogleMap = function (e) { 
    if (__listData && __listData.TotalResultCount > 0) { 
    __mapButton.toggleClass("opened"); 

    var __isVisible = $(__mapID).is(':visible'); 

    if (__isVisible) { 
    $(__mapID).show(); 
    if (!__isRendered) { 
     $(__mapID).empty(); 
    } 
    __mapButton.text(__mapButtonText.show); 
    } 
    else { 
    $(__mapID).show(); 
    __mapButton.text(__mapButtonText.show); 
    } 

    if (__isMapCreated) return 0; 

    __isMapCreated = 1; 

回答

1

將您的代碼放在點擊功能之外,但放置在文檔的就緒功能之外。

$(document).ready(function() { 
this.renderGoogleMap = __renderGoogleMap; 
var __renderGoogleMap = function (e) { 
    if (__listData && __listData.TotalResultCount > 0) { 
    __mapButton.toggleClass("opened"); 

    var __isVisible = $(__mapID).is(':visible'); 

    if (__isVisible) { 
    $(__mapID).show(); 
    if (!__isRendered) { 
     $(__mapID).empty(); 
    } 
    __mapButton.text(__mapButtonText.show); 
    } 
    else { 
    $(__mapID).show(); 
    __mapButton.text(__mapButtonText.show); 
    } 

    if (__isMapCreated) return 0; 

    __isMapCreated = 1; 
} 
+1

如果你覺得這篇文章有用,請記得選擇它作爲答案:) – ateich 2014-12-31 22:26:41