輸入框檢索內容,html標籤內檢索
阿新 • • 發佈:2020-08-19
@{ ViewData["Title"] = $"驗收部位"; } <div class="row no-gutters align-items-center"> <div class="col-3">關鍵詞查詢:</div> <div class="col-6 search_box"><input type="text" class="form-control" placeholder="請輸入關鍵詞" id="search"> </div> <div class="col-1"></div> <div class="col-2"> <button type="button" class="btn btn-primary btn-sm">新建</button> </div> </div> <hr /> <div class="search_content search_default"> <ul class="list-group list-group-flush" id="childList"> <li class="list-group-item"><a>8軸交G軸</a></li> <li class="list-group-item"><a>8軸交Y軸</a></li> <li class="list-group-item"><a>8軸交J軸</a></li> <li class="list-group-item"><a>8軸交H軸</a></li> <li class="list-group-item"><a>8軸交U軸</a></li> </ul> </div> @section styles{ } @section scripts{ <script type="text/javascript"> $(function () { var search_input = $(".search_box input"), search_content = $(".search_content"); $(search_input).on("keyup", function () { if (search_input.val() == '') { $(search_content).show(); } $(".search_content li:contains(" + search_input.val().trim() + ")").show(); $(".search_content li:not(:contains(" + search_input.val().trim() + "))").hide(); }); }); </script> }