如何在javascript中执行某个脚本?

时间:2018-03-29 00:27:52

标签: javascript jquery

我的javascript代码如下:

;(function($){

    $.ag.hideScrollbar = function (currentWidth) {
        ...
    };

    // not executed
    //start
    $.ag.initMap = function(mapCanvas){
        ...
    };
    $.ag.initMapAutocomplete = function () {
        ...
    };
    //end

}(jQuery));

我希望地图脚本不被执行

我不想评论这个剧本。我想为脚本添加一个不运行的条件

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以向该函数添加if语句

类似的东西:



;(function($) {

  if (element.length > 0) { //or whatever condition you need to test
    $.ag.hideScrollbar = function(currentWidth) {
      ...
    };
  }

  // not executed
  //start
  $.ag.initMap = function(mapCanvas) {
    ...
  };
  $.ag.initMapAutocomplete = function() {
    ...
  };
  //end

}(jQuery))