我如何调用内部函数onChange of selectize?

use*_*015 4 selectize.js

我如何调用内部函数onChange of selectize?

onChange: function(value){
  weatherWidget(value)
}

$(document).ready(function() {
  function weatherWidget(location){
    console.log('test');
  }
}
Run Code Online (Sandbox Code Playgroud)

这段代码给了我没有定义的功能.谢谢

bas*_*her 8

你有一个范围问题.您也可以将您的选择性调用$(document).ready包装起来(不管它应该包装在哪里),或者只是将函数声明留在它之外,因为它将在解析时加载.我建议将函数保留在外面$(document).ready,如下所示:

$(document).ready(function() {
  $(x).selectize({
    ....
    },
    onChange: function(value) {
      weatherWidget(value);
    }
  });    
});

function weatherWidget(location) {
  console.log(location);
}
Run Code Online (Sandbox Code Playgroud)