我想用自动建议制作一个多标签并用逗号分隔。我有一个问题。每次我从建议结果中单击。它总是被新值替换。
这是我的代码:
HTML:
<input type="text" id="ftags" autocomplete="off" value="" name="tags" onkeyup="lookup(this.value);">
<div id="suggestions" style="top: 26px; display: block;">
<p id="searchresults">
<span class="category">AirCraft</span>
<a href="#" class="searchlink" id="data_1"><span class="searchheading" data="Ace Aviation" id="span_1">Ace Aviation</span></a>
<a href="#" class="searchlink" id="data_2"><span class="searchheading" data=" Ackland" id="span_2"> Ackland</span></a>
<a href="#" class="searchlink" id="data_3"><span class="searchheading" data="Adam Aircraft" id="span_3">Adam Aircraft</span></a><span class="seperator">
<a href="" title="Sitemap">Nothing interesting here? Try the sitemap.</a>
</span>
<br class="break">
</p>
</div>
jQuery
function lookup(inputString) {
if(inputString.length == 0) {
$('#suggestions').fadeOut(); // Hide the suggestions box
} else {
$.post("modul/mod_album/rpc.php", {queryString: ""+inputString+""}, function(data) { // Do an AJAX call
$('#suggestions').fadeIn(); // Show the suggestions box
$('#suggestions').html(data); // Fill the suggestions box
});
}
}
$('.searchlink').click(function(e) {
var parent = $(this).closest('a').attr('id').replace('data_','');
var val_data = $("#span_"+parent).attr('data');
var ftag = $("#ftags").val();
$("#ftags").val(val_data).focus();
e.preventDefault();
})