随笔加载百度请求;无他随笔记录
<!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>