我有<input type = "text">
绑定了“keypress”事件,如下所示(请参阅jsfiddle: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>
我的问题是,如果我为该字段选择了一个浏览器建议(之前输入的值),那么keyup事件将不会触发。您有什么建议我应该解决这个问题?
测试了铬17和Firefox 10
一如既往地谢谢
答案 0 :(得分:0)
尝试绑定keyup
和change
。
$('#text_id').on('keyup change', function () {
// Code that works well for both cases, since they are
// a bit different.
})
答案 1 :(得分:0)
我最终将'autocomplete = off'设置为我的字段以防止这种情况发生