如何显示jQuery实例的所有键和值。我写了这段代码,但是没用。
html:
<input id="a" type="text">
jQuery:
$(function() {
$("#a").autocomplete({
source:["abc","def","ghi"]
});
var t="<div class='show'>";
$.each($("#a").autocomplete( "instance" ),function(key,value){
t+= key +" = " + value + "</br>";
});
t+="</div>";
$("body").append(t);
});
此错误jquery-1.10.2.js:516 Uncaught Error: no such method 'instance' for autocomplete widget instance
答案 0 :(得分:1)
如果您使用的是jQuery UI版本1.10.2,则它将不包含instance
方法,并且您将不得不返回到.data()
调用。
$(function() {
$("#a").autocomplete({
source: ["abc", "def", "ghi"]
});
var t = "<div class='show'>";
$.each($("#a").data("ui-autocomplete"), function(key, value) {
t += key + " = " + value + "</br>";
});
t += "</div>";
$("body").append(t);
})
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.2/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<input id="a" type="text">
查看更多:https://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/
将来,您可能希望使用jquery-ui
更好地标记您的帖子,以便获得更多具体帮助。
希望有帮助。