use*_*599 1 html javascript jquery internet-explorer
我刚刚意识到这段代码在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);
});
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你想检测输入字段的变化,然后做一些动作,对吗?
我认为您可能只检测更改而不是键盘操作.例如,如果用户从剪贴板粘贴怎么样?
请尝试以下代码:
$('#inputField').bind('propertychange input paste', function() {
// do poppularListBox()
});
Run Code Online (Sandbox Code Playgroud)
它适用于大多数输入字段,包括textarea.请查看jQuery站点以获取更多信息.
根据我的经验,.keyup()和.keypress()经常在IE中出错.我想尽可能使用.keydown()(个案)