直播系统搭建,可自动模糊匹配的搜索下拉框
直播系统搭建,可自动模糊匹配的搜索下拉框
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=
, initial-scale=1.0">
<title>Document</title>
</head>
<body>
搜索:<input type="text"><br>
<ul>
</ul>
</body>
</html>
<script>
let oInput=document.querySelector('input');
let oUl=document.querySelector('ul');
oInput.oninput=function (){
if(this.value != ""){
let xhr=new XMLHttpRequest();
xhr.open('GET','sousuo.php?wd='+this.value,true);
xhr.send();
xhr.onreadystatechange=function (){
if(xhr.readyState==4 && xhr.status==200){
fun(xhr.responseText);
console.log(xhr.responseText);
}
}
}else{
oUl.innerHTML = "";
}
}
function fun(resText){
//拼接
let strHtml='';
//将JSON形式的字符串转为数组
let obj=JSON.parse(resText);
for(let index in obj){
strHtml += `<li>${obj[index]}</li>`;
}
oUl.innerHTML = strHtml;
}
</script>
以上就是直播系统搭建,可自动模糊匹配的搜索下拉框, 更多内容欢迎关注之后的文章