欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS實(shí)現(xiàn)百度搜索接口及鏈接功能實(shí)例代碼

 更新時(shí)間:2018年02月02日 15:46:20   作者:Web攻城獅  
這篇文章主要介紹了JS實(shí)現(xiàn)百度搜索接口及鏈接功能實(shí)例代碼,需要的朋友可以參考下

本文通過代碼給大家介紹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ì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論