Py学习  »  Jquery

显示jquery ui“instance”方法的键和值

taher • 4 年前 • 643 次点击  

如何显示jQuery实例的所有键和值。我写了这段代码但没用。

html格式:

<input id="a" type="text">

查询:

$(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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50710
 
643 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Twisty
Reply   •   1 楼
Twisty    4 年前

如果您使用的是jqueryuiversion1.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 所以你可以得到更具体的帮助。

希望能有所帮助。