Skip to main content
 首页 » 编程设计

jquery之Bootstrap 标签输入无法使用文档就绪

2026年10月07日4shihaiming

我有这个函数 bootstrap tags input插件:

$(document).ready(function () { 
    $('input').tagsinput({ 
        typeahead: { 
            source: function (query) { 
                return $.getJSON('citynames.json'); 
            } 
        } 
    }) 
}); 

但是这个插件不起作用。我认为它与 jQuery (document).ready 有冲突。我该如何解决这个问题?

JSFIDDLE (为了更好地理解代码)

请您参考如下方法:

试试这个

$(document).ready(function () { 
    $('input').tagsinput({ 
        typeahead: { 
            source: function (query, process) { 
                process($.getJSON('citynames.json')); 
            } 
        } 
    }) 
});