gpt4 book ai didi

jquery - element.trigger() 在 IE 中不起作用

转载 作者:行者123 更新时间:2023-12-01 01:32:10 24 4
gpt4 key购买 nike

我用 AngularJS 实现了 jQuery 自动完成。

app.directive("autoComplete", function ($timeout) {
return {
restrict: "A",
link: function (scope, element) {
var location = ["OMAHA, NE", "OMAHA, TX", "DALLAS, TX", "DALLAS, NE"];

element.autocomplete({
source: location,
autoFocus: true,
delay: 0,
minLength: 3,
select: function () {
$timeout(function () {
element.trigger("input");
}, 0);
}
});
}
}
});

之前,从下拉列表中选择的自动完成值无法传递给 ngModel( JSFiddle example )。然后我添加了 element.trigger("input");,一切正常(在 Chrome 或 Firefox 中)。

但是,该问题在 IE 中仍然存在(我使用的是 IE 11)。当使用“Enter”或“左键单击”或“Tab”从下拉列表中选择自动完成值时,无法将其传递给 ngModel。所以原因是 element.trigger("input");不知何故在 IE 中不起作用。

感谢任何帮助。谢谢!

最佳答案

解决办法是:

select: function() {
$timeout(function() {
//Assign the selcted value to ngModel: scope.<ngModelValue> = <selectedValue>;
}, 0);
}

关于jquery - element.trigger() 在 IE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36869698/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com