码迷,mamicode.com
首页 > 其他好文 > 详细

跨域解决请求限制(script标签)(热门搜索出现对应的词条)

时间:2017-01-19 14:23:16      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:输入关键字   for   标签   doc   get   length   input   this   tee   

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>热门搜索</title>
</head>
<style>
  ul{
    list-style: none;
    color:pink;
  }
</style>
<body>
  <form action="">
    <input type="text" class="search" id= ‘search‘ placeholder="请输入关键字">
    <ul id= "search-list"></ul>
  </form>
</body>
<script>
  function searchResult(json){
    var oUl = document.getElementById(‘search-list‘);
    var search = document.getElementById(‘search‘);
    oUl.innerHTML = ‘‘;
    var res = json.s;
    var len = res.length;
    for(var i = 0;i < len ;i++){
      var oNewLi = document.createElement(‘li‘);
      oNewLi.innerHTML = res[i];
      oUl.appendChild(oNewLi);
    }
  }
  window.onload = function(){
    var oInput = document.getElementById(‘search‘);
    oInput.onfocus = function(){
      this.value = ‘‘
    }
    oInput.onkeyup = function(){
      var url = ‘https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su?wd=‘+this.value+‘&cb=searchResult‘;
      var oS = document.createElement(‘script‘);
      oS.src = url;
      document.head.appendChild(oS);
    };
  };
</script>
</html>

  

跨域解决请求限制(script标签)(热门搜索出现对应的词条)

标签:输入关键字   for   标签   doc   get   length   input   this   tee   

原文地址:http://www.cnblogs.com/TTTK/p/6306296.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!