Chạy ❯
Nhận trang web của
riêng
bạn
×
Thay đổi định hướng
Lưu mã
Thay đổi chủ đề, Tối/Sáng
Đi tới Không gian
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="https://maxcdn. bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js" ></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> </head> <body> <div class= "container"> <h2>Lọc mọi thứ</h2> <p>Nhập nội dung nào đó vào trường nhập để tìm kiếm văn bản cụ thể bên trong phần tử div với id="myDIV":</p> <input class="form- control" id="myInput" type="text" placeholder="Search.."> <div id="myDIV"> <p>Tôi là một đoạn văn.</p> <div>Tôi là một phần tử div bên trong div .</div> <button class="btn">Tôi là một nút</button> <button class="btn btn-info">Một nút khác</button> <p>Một đoạn khác.</p> </ div> </div> <script> $(document).ready(function(){ $("#myInput").on("keyup", function() { var value = $(this).val(). toLowerCase(); $("#myDIV *").filter(function() { $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) }); }); }); </script> </body> </html>