简体   繁体   中英

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:

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

This is my Javascript Code:

<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. and I am not even sure its related to the problem. My html code isn't changing at all!

Just wrap your JS code in a $(document).ready . You can see it working here: 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})  
});​

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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