這里的簡單代碼正在嘗試自動建議
這是我寫在 .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')
看不到任何動作。輸入之后,當我從文本框出來時。上面的錯誤出現在控制臺中,請幫幫我。并分享鏈接,我可以在其中學習和實施有關自動建議的資訊
uj5u.com熱心網友回復:
從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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/497392.html
標籤:javascript jQuery 自动完成
