首页 > 代码库 > jsonp_百度联想

jsonp_百度联想

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
请输入关键词<input id="keyword" type="text" value="" onkeyup="sugesst()"/>
<ul id="list">

</ul>
<script>
//http://suggestion.baidu.com/su?wd=‘+keyword+‘&cb=show
function show(allData) {
var data = http://www.mamicode.com/allData.s;
/*var str=‘‘;
data.forEach(function (item) {
str+=‘<li>‘+item+‘</li>‘;
document.querySelector("#list").innerHTML=str;
});
if(document.querySelector("#keyword").valuehttp://www.mamicode.com/==""){
document.querySelector("#list").innerHTML="";
}*/
//上边太麻烦,用map,map本身有返回值
var strArr=data.map(function(item) {
return ‘<li>‘+item+‘</li>‘;
}).join();
document.querySelector("#list").innerHTML=strArr;
console.log(typeof strArr);
}
function sugesst() {
var script = document.createElement("script");
var keyword=document.querySelector("#keyword").value;
script.src = http://www.mamicode.com/‘http://suggestion.baidu.com/su?wd=‘ + keyword + ‘&cb=show‘;
document.querySelector("body").appendChild(script);
}
</script>
</body>
</html>

jsonp_百度联想