JS实现百度搜索接口及链接功能实例代码
本文通过代码给大家介绍js实现百度搜索接口及链接功能,具体代码如下所示:
在上篇文章给大家介绍了JS 实现百度搜索功能
<!DOCTYPE html> <html ng-app="myApp"> <head> <meta charset="UTF-8"> <title>anchor</title> <style> *{ margin:0; padding:0; } #wei{ width:500px; height:600px; margin:0 auto; border:0px solid gray; } #wei input{ width:476px; height:50px; line-height: 50px; padding-left:20px; font-size: 16px; } #wei ul{ height:auto; border:1px solid #ccc; display: none; } #wei ul li{ width:100%; height:30px; line-height: 30px; text-indent:10px; font-size: 16px; list-style: none; } #wei ul li a{ text-decoration:none; } #wei ul li:hover{ display:block; background:#ccc; color:#fff; } </style> </head> <body ng-controller="show"> <div id="wei"> <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>
总结
相关推荐
rojyang 2020-05-20
ELEMENTS爱乐小超 2020-05-07
baynkbtg 2019-11-02
ksjlhy 2019-10-28
geminihr 2015-03-19
chang00 2015-06-17
LinSeeker 2019-09-07
nextwhy 2012-09-09
tongjianru 2011-05-18
Jarvan 2016-09-25
fadacai0 2016-04-18
deusrwvf 2017-06-21
AIOps智能运维 2015-05-25
magvwiz 2013-10-18
AIOps智能运维 2010-08-17
linqiang 2010-02-04
XSxing 2019-06-30