【问题标题】:custom values for chosen-Plugin选择插件的自定义值
【发布时间】:2014-09-04 06:39:09
【问题描述】:

是否可以为(选择)Chosen 插件输入自定义值,以创建自己的值作为选项?

http://harvesthq.github.io/chosen/

【问题讨论】:

标签: jquery jquery-chosen


【解决方案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');

                            }
                    }); 
            }

【讨论】:

    猜你喜欢
    • 2017-09-25
    • 1970-01-01
    • 2021-07-27
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 2012-05-18
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多