原生JS实现百度搜索api接口
来源:互联网 发布:百度网盘下载 知乎 编辑:程序博客网 时间:2024/06/07 00:34
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>api</title>
<style>
*{
margin:0;
padding:0;
}
#search-container{
width:500px;
height:600px;
margin:0 auto;
border:0px solid gray;
}
#search-container input{
width:476px;
height:40px;
line-height: 40px;
padding-left:20px;
font-size: 16px;
}
#search-container ul{
height:auto;
border:1px solid #ccc;
display: none;
}
#search-container ul li{
width:100%;
height:30px;
line-height: 30px;
text-indent:10px;
font-size: 16px;
list-style: none;
}
#search-container ul li a{
text-decoration:none;
}
#search-container ul li:hover{
display:block;
background:#ccc;
color:#fff;
}
</style>
</head>
<body ng-controller="show">
<div id="search-container">
<input type="text" id="text">
<ul id="list"></ul>
</div>
<script type="text/javascript">
var txt = document.getElementById("text");
var oUl = document.getElementById("list");
txt.onkeyup = function(){
var val = txt.value;
var oScript = document.createElement("script");//动态创建script标签
oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+val+"&cb=callback";
//添加链接及回调函数
document.body.appendChild(oScript);//添加script标签
document.body.removeChild(oScript);//删除script标签
}
//回调函数
function callback(data){
var str="";
for(var i=0;i<data.s.length;i++){
str += "<li><a href=\"https://www.baidu.com/s?wd="+data.s[i]+"\">"+data.s[i]+"</a></li>";
}
//console.log(str);
oUl.innerHTML=str;
oUl.style.display="block";
}
</script>
</body>
</html>
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>api</title>
<style>
*{
margin:0;
padding:0;
}
#search-container{
width:500px;
height:600px;
margin:0 auto;
border:0px solid gray;
}
#search-container input{
width:476px;
height:40px;
line-height: 40px;
padding-left:20px;
font-size: 16px;
}
#search-container ul{
height:auto;
border:1px solid #ccc;
display: none;
}
#search-container ul li{
width:100%;
height:30px;
line-height: 30px;
text-indent:10px;
font-size: 16px;
list-style: none;
}
#search-container ul li a{
text-decoration:none;
}
#search-container ul li:hover{
display:block;
background:#ccc;
color:#fff;
}
</style>
</head>
<body ng-controller="show">
<div id="search-container">
<input type="text" id="text">
<ul id="list"></ul>
</div>
<script type="text/javascript">
var txt = document.getElementById("text");
var oUl = document.getElementById("list");
txt.onkeyup = function(){
var val = txt.value;
var oScript = document.createElement("script");//动态创建script标签
oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+val+"&cb=callback";
//添加链接及回调函数
document.body.appendChild(oScript);//添加script标签
document.body.removeChild(oScript);//删除script标签
}
//回调函数
function callback(data){
var str="";
for(var i=0;i<data.s.length;i++){
str += "<li><a href=\"https://www.baidu.com/s?wd="+data.s[i]+"\">"+data.s[i]+"</a></li>";
}
//console.log(str);
oUl.innerHTML=str;
oUl.style.display="block";
}
</script>
</body>
</html>
0 0
- 原生JS实现百度搜索api接口
- 原生js仿百度搜索框
- js实现百度搜索接口及链接功能
- js实现百度搜索
- 模仿百度API接口搜索框
- Js实现百度搜索框提示功能(利用百度接口)
- jsonp结合百度接口-实现搜索功能
- js调用百度接口api接口添加标注
- js实现百度搜索结果翻页效果
- js/jQuery实现类似百度搜索功能
- Js+ajax实现智能百度搜索框
- js/jQuery实现类似百度搜索功能
- 百度地图之调用URL api接口实现周边搜索及计算球面两点间的距离
- js调用百度地图api实现定位
- js 百度地图API 搜索 返回 经纬度和地址
- 百度音乐搜索API
- 百度图片搜索api
- angularjs实现百度的搜索接口及链接的实现
- 巧用对象,生成不重复随机数
- iOS—协议语法
- css 4种引入方式
- spring学习链接
- 补MySQL第六天----Java中实现预处理、批处理、大数据字段与存储过程
- 原生JS实现百度搜索api接口
- 深入理解@ModelAttribute注解的工作过程
- STM32GPIO模式的理解
- An Experimental Study on Speech Enhancement Based on Deep Neural Networks学习摘要
- Windows下PhpEd将php升级到最新版本5.6.27,并支持Redis步骤
- 231. Power of Two
- 解决Activity嵌套碎片在fragment中操作Activity控制无效问题
- python5(字符串)
- 基于Visual attention的图片主题生成