keyup在IE 8中不起作用 [英] keyup not working in IE 8

查看:450
本文介绍了keyup在IE 8中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚意识到,这段代码在Firefox中运行良好,但不在IE 8中。当用户在输入字段中输入至少8个字符时,我需要自动填充列表。

  $('#inputField')。keyup(function(event){
var $ inputField = $(this);
if($ inputField.val()。length> = 8){popularListBox();}
});

函数populateListBox(){
$ .get(Default.aspx?name = test,function(data){
$('#listBox')。children ).remove();
var options = data;
$(#listBox)。html(data);
});


解决方案

您想检测更改在输入字段中,然后执行一些操作,对吗?



我认为您可能会检测到更改而不是键盘操作。例如,如果用户从剪贴板粘贴,怎么样?



请尝试以下代码:

 ($'code> $('#inputField')。bind('propertychange input paste',function(){
// do poppularListBox()
});

它适用于包括textarea在内的大多数输入字段。根据我的经验,.keyup()和.keypress()在IE中经常会遇到错误。如果可能的话,我想使用.keydown()(每个案例)


I just realized that this piece of code works well in Firefox but not in IE 8. I need to automatically populate the list when the user enters at least 8 characters in the input field.

$('#inputField').keyup(function (event) { 
    var $inputField = $(this); 
        if ($inputField.val().length >= 8) { popularListBox(); } 
});

function populateListBox(){
    $.get("Default.aspx?name=test", function(data) {
        $('#listBox').children().remove();
        var options = data;
        $("#listBox").html(data);
    });
}

解决方案

You want to detect the change in input field and then do some actions, right?

I think you may detect the changes instead of keyboard actions only. For example, how about if the user paste from clipboard?

Please try these codes:

$('#inputField').bind('propertychange input paste', function() {
  // do poppularListBox()
});

It works for most input field including textarea. Please check jQuery site for more information.

In my experience, .keyup() and .keypress() often get errors in IE. I would like to use .keydown() if possible (case by case)

这篇关于keyup在IE 8中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆