简体   繁体   English

通过JS代码填写自动完成输入

[英]Fill auto-complete input through JS code

I have an auto-complete input, works great .. 我有一个自动完成输入,效果很好..

When I fill the content through the JS code, it does not make it in the auto-complete, and I need him to do so. 当我通过JS代码填充内容时,它不会自动完成,我需要他这样做。

I tried to put the focus on the input, and run keypress event, it does not work ... What can I do? 我试着把重点放在输入上,并运行按键事件,它不起作用......我该怎么办?

Code (which fill in the input): 代码(填写输入):

function FillInput() {
        document.getElementById("MyInput").value ='xxx';
        $('.SearchCities').keypress();
        $('.SearchCities').focus();

    }

Try triggering the keyup event instead, as this is what autocomplete listens for. 尝试触发keyup事件,因为这是autocomplete监听的内容。 There probably aren't any handlers bound for keypress . 可能没有任何处理程序绑定到keypress

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

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