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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |