行测侠网站之题目搜索功能
2020-05-21
2 min read
搜题功能在此网站没有存在的必要,但是搜索功能还是很有必要记录学习。
<button style="float:right;margin-left:3px;margin-right:8px;margin-top: 1px;" onclick="soti();">搜索</button>
<input style="width:170px;float:right;margin-right:8px;" type="text" id="soti" placeholder=" 搜索题目" onkeydown="keyup_submit(event);">
<script>
function keyup_submit(e){
//回车键触发搜题
var evt = window.event || e;
if (evt.keyCode == 13){
document.getElementById("next").style.display="none";
var str=document.getElementById("soti").value;
souti(str);
}
}
function souti(str)
{
if (str=="")
{ document.getElementById("soti").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{xmlhttp=new XMLHttpRequest();}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{document.getElementById("timu").innerHTML=xmlhttp.responseText; }
}
xmlhttp.open("POST","so.php",true);
xmlhttp.setRequestHeader("Content-type","application/ x-www-form-urlencoded");
xmlhttp.send("soti="+str);
}
</script>
php核心代码
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$soti = test_input($_POST["soti"]);}
$result = mysql_query("SELECT * FROM xingce_panduan where timu like '%$soti%'");