我有一個搜索框在頁面的頂部。使用Ajax我想要一個div下拉頁面以顯示搜索結果。關鍵是我希望搜索結果覆蓋下面的頁面,而不是推下去。出於這個原因,我不能只在搜索框下面有一個div。我需要做一些更復雜的事情 - 但我不確定是什麼。javascript/php div下拉搜索結果
以下代碼在搜索框下面填充div。任何人都可以建議一種經濟的方式來讓div瀏覽頁面,而不是把所有東西都推下來。感謝您的任何建議!
的JavaScript
function showResults(str) {
document.getElementById("results").innerHTML=xmlhttp.responseText;
document.getElementById("results").style.border="1px solid #A5ACB2";
//some ajax
xmlhttp.open("GET","search.php?str="+str,true);
xmlhttp.send();
}
HTML
<html>
<body>
<table><tr><td><img src="logo.gif"></td><td>
<input type="text" id="string" onkeyup="showResults(this.value)">
<div id="results"></div><td></tr>
<tr><td colspan=2
Main body of page. All sorts of text and html go here that I do not want pushed down.
</td></tr></table>
</body>
</html>
絕對可以。 – j08691
絕對定位div嗎? – user1260310