是否可以为(select)Chosen
插件输入自定义值,以创建自己的值作为选项?
答案 0 :(得分:1)
是的,可以在onClick上调用此函数并在参数
中传递自定义值 function customTags(tagName)
{
var customTagLength = $('li.search-choice').length; //Custom Option length -1 as compare to actual Option length
if(customTagLength>9)
{
return false;
}
// above code to limit select value in chosen
var html = '<option value="'+tagName+'">'+tagName+'</option>';
$('.chosen-select').append(html);
//This is what you need
var SearchChoiceArrayTagName = [tagName];
$('.chosen-select').find('option').filter(function (idx, option) {
if($.inArray(option.value, SearchChoiceArrayTagName) !== -1) {
return option;
}
}).prop('selected', 'true');
$('.chosen-select').trigger("chosen:updated");
$('.chosen-select').chosen().change(function(e, params){
if(params.deselected==tagName)
{
$(".chosen-select option[value='"+tagName+"']").remove();
$(".chosen-select").trigger('chosen:updated');
}
});
}