[英]JQuery (Mobile) / JavaScript Select option cannot be selected
I have created a search filter that detaches the options that does not match with what the user has entered. 我创建了一个搜索过滤器,该过滤器可分离出与用户输入的内容不匹配的选项。
For example, the list contains: "hello", "good bye", "halo", and if I enter "h" then it'll only show "hello" and "halo". 例如,列表包含:“ hello”,“再见”,“光晕”,如果我输入“ h”,则仅显示“ hello”和“ halo”。
The problem I'm facing is that if there is one option I cannot select it, but if there are multiple options I can. 我面临的问题是,如果有一个选项,我将无法选择它,但是如果有多个选项,我可以选择它。
Here is the (full code) JSFiddle: JSFIDDLE LINK 这是(完整的代码)JSFiddle: JSFIDDLE LINK
To recreate the problem: Enter "another" in the input box, and try select the "do another" option in the select menu. 要重现该问题:在输入框中输入“另一个”,然后尝试在选择菜单中选择“执行另一个”选项。
I can select any option if there are more than one, so if I enter the word, "do", then I can select either options with that word inside. 如果有多个选项,我可以选择任何选项,因此,如果输入单词“ do”,则可以在其中带有该单词的情况下选择任一选项。
var probOptions = $("#problem>option");
function searchFilter() {
$("#searchInput").change(function() {
var searchString = $(this).val().toLowerCase();
$("#problem").empty().append(probOptions);
$("#problem>option").each(function() {
var text = $(this).text().toLowerCase();
if (text.indexOf(searchString) <= -1) {
$(this).detach();
// THE LINE BELOW FIXES THE PROBLEM (THE LINE BELOW IS NEWLY ADDED)
$("#problem").selectmenu("refresh");
}
});
});
}
searchFilter();
I managed to fix the problem myself. 我设法自己解决了这个问题。
Apparently for JQuery mobile you need to refresh the list, but standard JQuery you don't need to. 显然,对于JQuery移动版,您需要刷新列表,但是不需要刷新标准JQuery。
Here's the solution (where #problem is the ID of the select menu): 解决方法如下(其中#problem是选择菜单的ID):
$("#problem").selectmenu("refresh");
Hope this helps anyone that have this problem. 希望这对有此问题的任何人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.