我正在使用 jQuery 的自动完成插件来创建清单。有一系列问题,但幸运的是得到了除 1 之外的所有问题的解决方案。我剩下的问题是,当我单击任何复选框时,它不会保留其状态。如果单击列表项,我还想检查复选框。
HTML:
<input type='text' id='inTestField' name ='inTestField' />
<input type='hidden' id='TestField' name ='TestField' />
JS:
var cache = {},lastXhr,selectedItems;
var autoComplete = jQuery( '#inTestField').autocomplete
({
minLength: 1,
source : function( request, response ) {
var term = request.term;
type:'post';
// ajax request to server
},
delay: 800,
autoSelect :true,
open:
function( event, ui ){
selectedItems = new Array();
}
});
autoComplete.data('autocomplete').menu.options.selected = function(event, ui) {
var item = ui.item.data( 'item.autocomplete' );
if(!(item.value == '')){
selectedItems.push(item.value);
selectedItems = selectedItems.filter(function(elem, pos, self) {
return self.indexOf(elem) == pos;
});
document.getElementById('TestField').value = selectedItems;
jQuery(this).val(selectedItems.length + 'items selected');
}
autoComplete.focus();
return false;
};
autoComplete.data( "autocomplete" )._renderItem = function( ul, item ) {
return jQuery( "<li></li>" )
.data( 'item.autocomplete', item )
.append( '<a><input type="checkbox" id="autoCheck_'+item.value+'" /> ' + item.label + '</a>' )
.appendTo( ul );
};
请提出任何需要的更改提前谢谢