js模糊查询select内容
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
:js模糊查询select内容 示例代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> </head> <body> <input type="text" id="searchInput" onkeyup="filterSelect()" placeholder="Search..."> <select id="mySelect"> <option value="apple">Apple</option> <option value="banana">Banana</option> <option value="orange">Orange</option> <option value="grape">Grape</option> </select> </body> <script> function filterSelect() { var input, filter, select, options, i, txtValue; input = document.getElementById("searchInput"); filter = input.value.toUpperCase(); select = document.getElementById("mySelect"); options = select.getElementsByTagName("option");
// Loop through all options, and hide those who don't match the search query for (i = 0; i < options.length; i++) { txtValue = options[i].textContent || options[i].innerText; if (txtValue.toUpperCase().indexOf(filter) > -1) { options[i].style.display = ""; } else { options[i].style.display = "none"; } } } </script> </html> 该文章在 2025/1/22 11:48:04 编辑过 |
关键字查询
相关文章
正在查询... |