<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
li{
list-style: none;
}
</style>
</head>
<body>
<span>hh</span>
<input id="search" type="text">
<ul id="list" class="kk"></ul>
</body>
<script>
class jsonpDemo {
constructor() {
this.search = search;
this.list = list;
this.body = document.body;
this.init();
};
init(){
this.watchInput();
};
watchInput() {
this.search.onkeyup = () => {
if(this.search.value.length == 0){
this.list.innerHTML='';
return;
}
const script = document.createElement('script');
script.src = "http://www.baidu.com/su?wd="+this.search.value+"&cb=jsonp.showMsg";
this.body.appendChild(script);
this.body.removeChild(script);
}
};
showMsg(msg) {
var str = '';
msg.s.forEach((item,i)=>{
str += '<li>' + item + '</li>';
});
this.list.innerHTML = str;
}
}
const jsonp = new jsonpDemo();
</script>
</html>
百度搜索框提示词
最新推荐文章于 2024-06-11 10:17:51 发布