Awesomplete - get selected text

人盡茶涼 提交于 2019-12-10 18:05:51

问题


Is there a straightforward way to get the text in an awesomplete field (https://leaverou.github.io/awesomplete/)?

var input = document.getElementById("inputlist");
alert(input.value);

shows NaN!


回答1:


You need to add the event either awesomplete-select or awesomplete-selectcomplete

In regular Javascript

var input = document.getElementById("inputlist"); 
new Awesomplete(input, {list: yourlist});
document.getElementById('inputlist').addEventListener('awesomplete-selectcomplete',function(){
  alert(this.value); 
});  

In Jquery

var input=$("#inputlist")[0];
new Awesomplete(input, {list: yourlist});
$("#inputlist").on('awesomplete-selectcomplete',function(){
  alert(this.value);
});


来源:https://stackoverflow.com/questions/35864545/awesomplete-get-selected-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!