gpt4 book ai didi

javascript - 搜索时jquery select2自定义javascript函数

转载 作者:行者123 更新时间:2023-11-29 19:15:48 26 4
gpt4 key购买 nike

我的页面中有几个 select2。我有一个特定的 ajax 引擎,由于多种原因无法更改它。我想在最终用户在字段中键入内容时填写每个 select2 下拉列表,并使用自制的 javascript 来填写 select2 中的“选项”。

我已经尝试了很多在网上找到的不同东西,但找不到适用的语法。

例如:

      jQuery("customer").select2({
query: function (options) {
alert('ok');
// my ajax call would be here
xajax_getCustomers(stringFilled);
}
});

我尝试过使用“ajax:”和其他一些东西,但我找不到如何在填充内容时触发 javascript 函数。重要提示:我应该能够填充字符串,以便将其传递给我的 ajax 调用

谢谢你的帮助

最佳答案

你有这个事件:

  $(selector).on("select2-highlight", function(e) {
console.log("highlighted val=" + e.val + " choice=" + e.choice.text);
})

它对搜索事件有效,所以当 select2-highlight 事件被触发时意味着用户正在搜索一个字符串,您可以使用 e.vale.choice.text 值。

不幸的是,没有严格的搜索事件,但您可以使用 on('keyup');

绑定(bind)插件的隐藏输入文本

像这样:

 $('input.select2-search__field').on('keyup', function() {
alert($(this).val()); // it alerts with the string that the user is searching
});

关于javascript - 搜索时jquery select2自定义javascript函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451524/

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