我在插件中看到了一个很好的标记自动完成字段WordPress Admin Style, 通过Frank Bueltge (设计管理页面非常重要)。列表是用JavaScript硬编码的,我们可以使用Ajax或wp_localize_script
得到真实的东西。
标记中是这样的:
<!-- Autocomplete -->
<h3 id="anker_autocomplete" class="demoAutocomplete">Autocomplete</h3>
<label for="autocomplete">Tags: </label>
<input id="autocomplete" type="text" />
以及jQuery:
// autocomplete
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"etc..."
];
$( "#autocomplete" ).autocomplete({
source: availableTags
});
$( "#autocomplete-core" ).autocomplete({
source: availableTags,
position: ( \'undefined\' !== typeof isRtl && isRtl ) ? { my: \'right top\', at: \'right bottom\', offset: \'0, -1\' } : { offset: \'0, -1\' },
open: function() { $(this).addClass(\'open\'); },
close: function() { $(this).removeClass(\'open\'); }
});
最后,使此字段可重复: