跨域解决请求限制(script标签)(热门搜索出现对应的词条)
<!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>