3
回答
PHP中可编辑下拉框的编写 ---jquery---不知道数组如何传递进去
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

目前在做PHP中可编辑下拉框,在jquery上下载了一段代码如下:

<!doctype html>
 
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Categories</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <style>
  .ui-autocomplete-category {
    font-weight: bold;
    padding: .2em .4em;
    margin: .8em 0 .2em;
    line-height: 1.5;
  }
  </style>
  <script>
  $.widget( "custom.catcomplete", $.ui.autocomplete, {
    _renderMenu: function( ul, items ) {
      var that = this,
        currentCategory = "";
      $.each( items, function( index, item ) {
        if ( item.category != currentCategory ) {
          ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
          currentCategory = item.category;
        }
        that._renderItemData( ul, item );
      });
    }
  });
  </script>
  <script>
  $(function() {
    var data = [
      { label: "anders", category: "" },
      { label: "andreas", category: "" },
      { label: "antal", category: "" },
      { label: "annhhx10", category: "" },
      { label: "annk K12", category: "" },
      { label: "annttop C13", category: "" },
      { label: "anders andersson", category: "" },
      { label: "andreas andersson", category: "" },
      { label: "andreas johnson", category: "" }
    ];
	
    $( "#search" ).catcomplete({
      delay: 0,
      source: data
    });
  });
  </script>
</head>
<body>
 
<label for="search">Search: </label>
<input id="search" />
 
 
</body>
</html>
运行效果图:

我现在有个疑问是:比如我有个PHP的数组:

<?php
	$users = array();
	$users[0] = "aaa";
	$users[1] = "aab";
	$users[2] = "aac";
 ?>
我如何把$users嵌入到刚才的那段代码中,代替data呢?这样我就可以搜寻“aaa”,"aab","aac"了???

<无标签>
举报
fzyz_sb
发帖于4年前 3回/1K+阅
顶部