您好,登錄后才能下訂單哦!
本文通過(guò)代碼給大家介紹js實(shí)現(xiàn)百度搜索接口及鏈接功能,具體代碼如下所示:
在上篇文章給大家介紹了JS 實(shí)現(xiàn)百度搜索功能
<!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");//動(dòng)態(tài)創(chuàng)建script標(biāo)簽 oScript.src = "https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd="+val+"&cb=callback"; //添加鏈接及回調(diào)函數(shù) document.body.appendChild(oScript);//添加script標(biāo)簽 document.body.removeChild(oScript);//刪除script標(biāo)簽 } //回調(diào)函數(shù) 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>
總結(jié)
以上所述是小編給大家介紹的JS實(shí)現(xiàn)百度搜索接口及鏈接功能實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。