[英]How to use functions in open-source javascript file
我正在使用開源 javascript 文件。 我想在我自己的代碼中使用它的代碼中有一個 function。 我的文件結構是這樣的:
function ($) {
// there is codes here
function _disable(input, v) { // I need this function
_o(input).prop('disabled', v);
input.prop('disabled', v);
var input_div = _getInputpickerDiv(input);
if (v) {
input_div.find('.inputpicker-arrow').hide();
}
else {
input_div.find('.inputpicker-arrow').show();
}
}
// there is codes here
});
我參考了開源文件並嘗試了以下代碼:
<script src="assets/jquery.inputpicker.js"></script>
$("input").each(function () {
_disable($(this), false);
});
但我收到此錯誤:
未捕獲的 ReferenceError:_disable 未定義
誰能幫我這個?
您可以像這樣設置全局變量:
function ($) {
// there is codes here
function _disable(input, v) { // I need this function
_o(input).prop('disabled', v);
input.prop('disabled', v);
var input_div = _getInputpickerDiv(input);
if (v) {
input_div.find('.inputpicker-arrow').hide();
}
else {
input_div.find('.inputpicker-arrow').show();
}
}
// there is codes here
// make it available outside the scope
window._disable = _disable
});
然后像這樣訪問它:
_disable(...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.