简体   繁体   English

将数据通过Javascript传递给Bootstrap Typeahead

[英]Pass data trough Javascript to Bootstrap Typeahead

Guys I am trying to pass some data to my typeahead form, but for some reason my code isn't working: 伙计们,我正在尝试将一些数据传递给我的提前输入表单,但是由于某种原因,我的代码无法正常工作:

This is my HTML CODE: 这是我的HTML代码:

<input type="text" class="span3" id="getsourCe" data-provide="typeahead" data-items="4" />

This is my Javascript Code: 这是我的Javascript代码:

<script>  
var programLang = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3', 'JSON'];   
$('#getsourCe').typeahead({source: programLang})  
</script>  

The only error I'm getting is Uncaught SyntaxError: Unexpected token. 我得到的唯一错误是未捕获的SyntaxError:意外令牌。 and I am not even sure its related to the problem. 我什至不确定它与问题有关。 My html code isn't changing at all! 我的html代码完全没有改变!

Just wrap your JS code in a $(document).ready . 只需将您的JS代码包装在$(document).ready You can see it working here: http://jsfiddle.net/EkFQP/ 您可以在这里看到它的工作: http : //jsfiddle.net/EkFQP/

Here's the code: 这是代码:

$(document).ready(function() {
     var programLang = ['PHP', 'MySQL', 'SQL', 'PostgreSQL', 'HTML', 'CSS', 'HTML5', 'CSS3', 'JSON'];   
     $('#getsourCe').typeahead({source: programLang})  
});​

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM