/* 手机适配 */ @media screen and (max-width: 500px) { .search{ padding-right: 25px; } .search input{ width: 100%; } .search button{ display: none; } } /* 电脑适配 */ @media screen and (min-width: 500px) { .search{ width: 500px; } .search input{ width: 444px; } } /* 通用样式 */ .search{ margin: auto; } .search input{ outline: none; border: 2px solid #c05b4d; height: 32px; padding: 10px; } .search button{ outline: none; border: 0px; height: 56px; width:56px; position:absolute; background-color:#c05b4d ; } .search .icon{ width: 28px; height: 28px; } 搜索中,请稍后 ... // enter window.onload = function() { document.onkeydown = function(ev) { var event = ev || event if (event.keyCode == 13) { search() } } } // search function search() { key = document.getElementById("search-key").value; if (key === "") { return; } document.getElementById("search-key").value = ""; // tip document.getElementById("search-tip").innerText = "搜索中,请稍后 ..."; document.getElementById("search-tip").style.display = "block"; // clear var el = document.getElementById('result'); var childs = el.childNodes; for (var i = childs.length - 1; i = 0; i--) { el.removeChild(childs[i]); } // xml xmltext = new XMLHttpRequest; xmltext.open("GET", "/index.xml", false); xmltext.send(); resp = xmltext.responseXML; items = resp.getElementsByTagName("item"); // search var i = 0; haveResult = false; while (i -1) { haveResult = true; title = items[i].getElementsByTagName("title")[0].innerHTML; link = items[i].getElementsByTagName("link")[0].innerHTML; time = items[i].getElementsByTagName("pubDate")[0].innerHTML; mark = items[i].getElementsByTagName("description")[0].innerHTML; addItem(title, link, time, mark) } i++; } if (!haveResult) { document.getElementById("search-tip").innerText = "搜索完毕,未发现结果 ..."; document.getElementById("search-tip").style.display = "block"; } } // add function addItem(title, link, time, mark) { document.getElementById("search-tip").style.display = "none"; tmpl = "" + "" + "" + title + "" + "" + " " + time + "" + "" + " " + "" + "" + mark + "" + "" + "阅读更多" + "" + " " + "" div = document.createElement("div") div.innerHTML = tmpl; document.getElementById('result').appendChild(div) }