菜鸟练网页 Posted on 2017-11-13 | In java设计模式 | 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990<!DOCTYPE html><html><meta charset="utf-8"><title>菜鸟练网页</title><style media="screen">input[type=text] { width: 130px; box-sizing: border-box; border: 2px solid #ccc; border-radius: 4px; font-size: 16px; background-color: white; background-image: url('searchicon.png'); background-position: 10px 10px; background-repeat: no-repeat; padding: 12px 20px 12px 40px; -webkit-transition: width 0.4s ease-in-out; transition: width 0.4s ease-in-out;}input[type=text]:focus { width: 100%;}body{ background-image: url('http://p1.bqimg.com/567571/1487e5929ef40176.jpg');}#myInput { background-image: url('https://static.runoob.com/images/mix/searchicon.png'); /* 搜索按钮 */ background-position: 10px 12px; /* 定位搜索按钮 */ background-repeat: no-repeat; /* 不重复图片 */ width: 100%; font-size: 16px; padding: 12px 20px 12px 40px; border: 1px solid #ddd; margin-bottom: 12px;}#myTable { border-collapse: collapse; width: 100%; border: 1px solid #ddd; font-size: 18px;}#myTable th, #myTable td { text-align: left; padding: 12px;}#myTable tr { /* 表格添加边框 */ border-bottom: 1px solid #ddd;}#myTable tr.header, #myTable tr:hover { /* 表头及鼠标移动过 tr 时添加背景 */ background-color: #f1f1f1;}</style><body> <input type="text" id="myInput" onkeyup="myFunction()" placeholder="搜索..."> <form> <input type="text" name="search" placeholder="Search.."> </form></body><script type="text/javascript">function myFunction() { // 声明变量 var input, filter, table, tr, td, i; input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); // 循环表格每一行,查找匹配项 for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[0]; if (td) { if (td.innerHTML.toUpperCase().indexOf(filter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } }}</script></html>