0

我正在使用波爾圖的自定義JQuery Bootstrap嚮導,我被要求使用 ,當使用鏈接時,它會在嚮導的相關選項卡上。如何將Javascript對象的所有屬性放置到另一個對象中?

,我唯一需要的是從以下對象變量檢索所有的屬性:

$('#w3').bootstrapWizard({ 
    tabClass: 'wizard-steps', 
    nextSelector: 'ul.pager li.next', 
    previousSelector: 'ul.pager li.previous', 
    previousLinkSelector: 'ul.pager li.finish a.previous-link', 
    firstSelector: null, 
    lastSelector: null, 
    onNext: function (tab, navigation, index, newindex) { 
     var validated = $('#w3 form').valid(); 
     if (!validated) { 
      $w3validator.focusInvalid(); 
      return false; 
     } 
    }, 
    onTabClick: function (tab, navigation, index, newindex) { 
     if (newindex == index + 1) { 
      return this.onNext(tab, navigation, index, newindex); 
     } else if (newindex > index + 1) { 
      return false; 
     } else { 
      return true; 
     } 
    }, 
    onTabChange: function (tab, navigation, index, newindex) { 
     var $total = navigation.find('li').size() - 1; 
     $w3finish[newindex != $total ? 'addClass' : 'removeClass']('hidden'); 
     $('#w3').find(this.nextSelector)[newindex == $total ? 'addClass' : 'removeClass']('hidden'); 
    }, 
    onTabShow: function (tab, navigation, index) { 
     var $total = navigation.find('li').length - 1; 
     var $current = index; 
     var $percent = Math.floor(($current/$total) * 100); 
     $('#w3').find('.progress-indicator').css({ 'width': $percent + '%' }); 
     tab.prevAll().addClass('completed'); 
     tab.nextAll().removeClass('completed'); 
    } 
}); 

我需要把它放在一個全局變量,所以我可以使用所有屬性 (尤其是onTabClick屬性)。

我試着做以下方式:

var $mainSettings = $.fn.bootstrapWizard; 

的問題是,$ mainSettings僅包括函數聲明。

什麼是從$ .fn.bootstrapWizard獲取所有屬性的正確方法; ?

回答

0

它取決於這個jquery插件如何公開它接收到的配置。如果它不暴露這個,那麼你的運氣不好。但是,您可以將配置分配給一個變量並將該變量傳遞給jquery插件。

var $mainSettings = { 
    tabClass: 'wizard-steps', 
    nextSelector: 'ul.pager li.next', 
    previousSelector: 'ul.pager li.previous', 
    previousLinkSelector: 'ul.pager li.finish a.previous-link', 
    firstSelector: null, 
    lastSelector: null, 
    onNext: function (tab, navigation, index, newindex) { 
     var validated = $('#w3 form').valid(); 
     if (!validated) { 
      $w3validator.focusInvalid(); 
      return false; 
     } 
    }, 
    onTabClick: function (tab, navigation, index, newindex) { 
     if (newindex == index + 1) { 
      return this.onNext(tab, navigation, index, newindex); 
     } else if (newindex > index + 1) { 
      return false; 
     } else { 
      return true; 
     } 
    }, 
    onTabChange: function (tab, navigation, index, newindex) { 
     var $total = navigation.find('li').size() - 1; 
     $w3finish[newindex != $total ? 'addClass' : 'removeClass']('hidden'); 
     $('#w3').find(this.nextSelector)[newindex == $total ? 'addClass' : 'removeClass']('hidden'); 
    }, 
    onTabShow: function (tab, navigation, index) { 
     var $total = navigation.find('li').length - 1; 
     var $current = index; 
     var $percent = Math.floor(($current/$total) * 100); 
     $('#w3').find('.progress-indicator').css({ 'width': $percent + '%' }); 
     tab.prevAll().addClass('completed'); 
     tab.nextAll().removeClass('completed'); 
    } 
}; 

$('#w3').bootstrapWizard($mainSettings); 
相關問題