textbox browser autocompletion options do not fire keypress/keyup

懵懂的女人 提交于 2019-12-25 00:49:05

问题


I have an <input type = "text"> binded with a "keypress" event, as follows (see jsfiddle here: http://jsfiddle.net/periklis/RMyc7/):

<form name = "myform" method = "post">
    <input type = "text" name = "mytext" id = "text_id"/>
    <input type = "submit"/>
</form>
<script>
$(document).ready(function() {
    $('#text_id').bind('keyup', function() {
        console.log('pressed!');
    });
});
</script>​

My problem is that if I select one of the browser recommendations for the field (previously entered values), then the keyup event won't fire. What do you suggest I should do to work around this?

Tested on chromium 17 and Firefox 10

Thanks as always


回答1:


Try binding to both keyup and change.

$('#text_id').on('keyup change', function () {
    // Code that works well for both cases, since they are
    // a bit different.
})



回答2:


I ended up setting 'autocomplete=off' to my field to prevent this from happening



来源:https://stackoverflow.com/questions/9531612/textbox-browser-autocompletion-options-do-not-fire-keypress-keyup

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