繁体   English   中英

Uncaught TypeError: Cannot read properties of undefined (reading 'length') 。 Jquery中的自动建议

[英]Uncaught TypeError: Cannot read properties of undefined (reading 'length') . auto-suggestion in Jquery

这里的简单代码正在尝试自动建议

这是我写在 .js 文件中的自动建议代码(在 (document).ready 函数内)

$(function () {
        var list = [
            "One",
            "two",
            "Three",
            "Four",
        ];
        debugger;
        $("#text").autocomplete({
           
            minLength: 0,
            delay: 0,  
            placeholder: "Select Transporter...",
            source: list
        });

html代码

<input type="text" id="text" value="text" />

错误显示为:

Uncaught TypeError: Cannot read properties of undefined (reading 'length')

看不到任何动作。输入之后,当我从文本框出来时。 上面的错误出现在控制台中,请帮帮我。 并分享链接,我可以在其中学习和实施有关自动建议的信息

https://jqueryui.com/autocomplete/确保您导入了这两个 CDN

<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>

最终代码会这样

<!doctype html>
<html>

<head>
    <title>Online jQuery Editor</title>
    <script src="https://code.jquery.com/jquery-3.6.0.js"></script>
    <script src="https://code.jquery.com/ui/1.13.1/jquery-ui.js"></script>
</head>

<body>
    <input type="text" id="text" value="text" />
</body>
<script>
    $(document).ready(function () {
        $(function () {
            var list = [
                "one",
                "two",
                "three",
                "four",
            ];
            debugger;
            $("#text").autocomplete({
                minLength: 0,
                delay: 0,
                placeholder: "Select Transporter...",
                source: list
            });
        })
    });
</script>

</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM