<style>
body{margin: 0;}
ul{margin: 0;padding: 0;list-style: none;}
a{color:inherit;text-decoration: none;}
input{padding: 0;border: 0;}
.box{width: 340px;height: 38px;border: 2px solid gray;}
.con{overflow: hidden;}
.input{float: left;width: 300px;height: 38px;}
.search{width: 38px;height: 38px;float: right;background: url('http://sandbox.runjs.cn/uploads/rs/26/ddzmgynp/search.png') 0 -38px;}
.list{position: absolute;width: 298px;border: 1px solid #e6e8e9; overflow: hidden;}
.in{line-height: 30px;border-bottom: 1px solid lightblue;cursor:pointer;text-indent: 1em;}
.list .in:last-child{margin-bottom: -1px;}
.in:hover{background-color: #f9f9f9;}
</style> <div class="box" id="box">
<div class="con">
<input class="input" id="search">
<a target="_blank" id="btn" href="javascript:;" class="search"></a>
</div>
<ul class="list" id="list"></ul>
</div>
<script>
function loadScript(url){
loadScript.mark = 'load';
var script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
document.body.appendChild(script);
}
function callback(data){
if(data){
var arr = data.s;
var html = '';
for(var i = 0,len = arr.length; i < len; i++){
html+= "<li class='in'><a href='https://www.baidu.com/s?wd="+ arr[i]+"' target='_blank' style='display:block'>" + arr[i]+ "</a></li>"
}
list.innerHTML = html;
}
}
search.onkeyup = function(e){
e = e || event;
if(e.keyCode == '13'){
window.open('https://www.baidu.com/s?wd=' + this.value);
}
if(this.value){
if(search.data != this.value){
btn.setAttribute('href','https://www.baidu.com/s?wd=' + this.value);
var that = this;
loadScript("https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=" + that.value + "&&cb=callback");
}
}else{
list.innerHTML = '';
}
search.data = this.value;
console.log( search.data ,this.value)
}
search.onclick = function(e){
e = e || event;
list.style.display = 'block';
if(e.stopPropagation){
e.stopPropagation();
}else{
e.cancelBubble = true;
}
}
document.onclick = function(){
list.style.display = 'none';
}
</script>

  

最新文章

  1. (转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
  2. 为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录
  3. SQL笔记 - CTE递归实例(续):显示指定部门的全称
  4. mysql建表建索引
  5. awk的二维数组
  6. iOS UIWebView加载时添加进度条
  7. ContentProvider(一)
  8. Spring+Maven+Eclipse构建Web工程
  9. ASP.NET设计模式(一)、适配器模式、依赖注入依赖倒置、空对象模式
  10. UITextField点击return后注销第一响应者
  11. Swiper滑动Html5手机浏览器自适应
  12. 无需Visual Studio,5容易的 - 分为报告
  13. Microsoft Web Test Recorder在录制时没有显示
  14. 1、初识Activity
  15. Objective-C优缺点
  16. 《算法》第三章部分程序 part 3
  17. Hibernate 一对一
  18. leetcode415
  19. JNI字段描述符
  20. pycharm安装与使用

热门文章

  1. POJ1847 Tram SPFA算法变形
  2. From表单提交刷新页面?
  3. Canvas 与 Image 相互转换
  4. CF352A Jeff and Digits
  5. CF708B Recover the String 构造
  6. Java实现几分钟之后调度任务的定时器
  7. README.md使用
  8. vue学习—组件的定义注册
  9. cf Permute Digits(dfs)
  10. buildKibanaServerUrl