<!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>

Logo

电商企业物流数字化转型必备!快递鸟 API 接口,72 小时快速完成物流系统集成。全流程实战1V1指导,营造开放的API技术生态圈。

更多推荐