隨筆百度jsonp請求

隨筆加載百度請求;無他隨筆記錄

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <style>
    div {
      width: 200px;
      height: 200px;
      margin: 10px;
      background-color: #ccc;
      float: left;
    }
  </style>
</head>

<body>
  <input type="text" id="input">
  <textarea name="" id="text" cols="30" rows="10"></textarea>
</body>
<script>
  function show(json) {
    let arr = [];
    if (!json.g) {
      text.value = '';
      return;
    }
    json.g.forEach(item => {
      arr.push(item.q);
    })
    text.value = arr.join(',');
  }
  window.onload = function () {
    let input = document.getElementById('input');
    let text = document.getElementById('text');
    input.oninput = function () {
      let Os = document.createElement('script');
      Os.src =`https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=30962,1467,31125,21116,31341,31217,30823,26350,31164&wd=${encodeURIComponent(input.value)}&cb=show`;
      document.head.appendChild(Os);
    }
  }
</script>

</html>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章