<!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">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.box {
width: 500px;
padding: 10px;
margin: 50px auto;
border: 1px solid #ccc;
}
input {
width: 100%;
height: 30px;
line-height: 30px;
}
ul {
list-style: none;
}
</style>
</head>
<body>
<div class="box">
<input type="text" id="inp">
<ul>
</ul>
</div>
<script>
let inp = document.querySelector('#inp')
let ul = document.querySelector('ul')
inp.oninput = function () {
if (inp.value.trim() === '') {
return
}
window.fn = function (data) {
// console.log(data.result)
let arr = data.result
if (arr) {
let str = '' //我的li数组
arr.forEach(item => {
console.log(item)
str += `<li>${item[0]}</li>`
});
ul.innerHTML = str
} else {
ul.innerHTML = ''
}
script.remove()
}
// console.log(script)
console.log(inp.value)
let script = document.createElement('script')
script.src = `https://suggest.taobao.com/sug?area=c2c&k=1&q=${inp.value}&code=utf-8&ts=1719969556947&callback=fn`
document.body.appendChild(script)
}
</script>
</body>
</html>
04-17
325
11-16
152
11-15
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交