所以,我现在正在为这样一个简单的问题而抓狂:一旦我选择了一个"typeahead“,它应该立即重定向到所属的页面。
不幸的是,由于某些原因,jsfiddle没有显示下拉菜单,所以我将其上传到了radom网站空间。http://ch1n3s3.funpic.de/lol/test3.php
代码是这样的:
<input id="id" autocomplete="off" name="name" type="text" data-provide="typeahead" data-items="4" data-source='["test", "test2", "test3"]'>
<script>
$('#id').on('change', function(){
var items = "'test', 'test2', 'test3'";
var matchString = "'"+$(this).val()+"'";
if (items.toLowerCase().indexOf(matchString.toLowerCase()) != -1){
alert('Matched');
}
else {
alert('Not Matched');
}
});
</script>有没有比这更简单、效果更好的解决方案?
谢谢你,克里斯
发布于 2013-03-08 22:43:11
你可以在typeahead提供的更新器函数中编写重定向请求,试一试,这肯定比这更好,但并不那么容易。
发布于 2017-10-22 20:17:37
解决方案
$('.typeahead').bind('typeahead:select', function(ev, suggestion) {
window.location.href = '/' + suggestion;
});例如,选择建议阿拉斯加将重定向到/Alaska。
https://stackoverflow.com/questions/13499029
复制相似问题