此代码用于我们网站上的自动填充框,我们希望将用户选择的数量限制为1.只允许一个选项。
// Downloads
$('input[name=\'download\']').autocomplete({
'source': function(request, response) {
$.ajax({
url: 'index.php?route=catalog/vdi_download1/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item['name'],
value: item['download_id']
}
}));
}
});
},
'select': function(item) {
$('input[name=\'download\']').val('');
$('#product-download' + item['value']).remove();
$('#product-download').append('<div id="product-download' + item['value'] + '"><i class="fa fa-minus-circle"></i> ' + item['label'] + '<input type="hidden" name="product_download[]" value="' + item['value'] + '" /></div>');
}
});
$('#product-download').delegate('.fa-minus-circle', 'click', function() {
$(this).parent().remove();
});