密钥在IE 8中不起作用

时间:2022-12-06 19:26:33

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.

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

$('#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);
    });
}

1 个解决方案

#1


5  

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.

它适用于大多数输入字段,包括textarea。请查看jQuery站点以获取更多信息。

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

根据我的经验,.keyup()和.keypress()经常在IE中出错。我想尽可能使用.keydown()(个案)

#1


5  

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.

它适用于大多数输入字段,包括textarea。请查看jQuery站点以获取更多信息。

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

根据我的经验,.keyup()和.keypress()经常在IE中出错。我想尽可能使用.keydown()(个案)