【发布时间】:2013-08-13 20:36:12
【问题描述】:
我有一个问题,在 chrome 和 IE 上获取事件“keypress”。 在 Firefox 上运行良好。
function bind_input_keypress ($this) {
$($this).bind('input', function() {
$($this).css('width',$($this).val().length*5.5+20);
})
$($this).bind('keypress',function(e) {
/* delete last extra... */
if( e.keyCode == '8' && $($this).val()=='' ) { $('#extras b').remove(); }
/* arrow up */
if( e.keyCode == '38' ) {
console.log('38 pressed');
}
/* arrow down */
if( e.keyCode == '40' ) {
console.log('40 pressed');
ad_curr = $('.ad_selectbox .autocomplete ul li.active');
}
});
}
$('input').focus(function(){
bind_input_keypress($(this));
})
为什么这在 chrome 和 IE 上不起作用?
你也可以在 jsfiddle 上查看 http://jsfiddle.net/a5M6S/2/
【问题讨论】:
-
在调用处理程序时您传递
$this而不是仅使用this是否有原因? -
另外请解释“不工作”。您是否在控制台上遇到错误?它应该做什么?它在做什么呢?
-
试试这个。 jsfiddle.net/R9unv我似乎无法发布答案。
标签: javascript jquery google-chrome firefox keypress