最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - multiselect checkbox dropdown - Stack Overflow

programmeradmin2浏览0评论

I am using multiselect checkbox dropdown.

Please look example jsfiddle

$(function () { $('#lstStates').multiselect({ }); });

Once you select states it show then TEXT value and concat with ma like: New Jersey, New York, Ohio

But I want VALUE of that selected ITEM like: NJ, NY, OH

I am using multiselect checkbox dropdown.

Please look example jsfiddle

$(function () { $('#lstStates').multiselect({ }); });

Once you select states it show then TEXT value and concat with ma like: New Jersey, New York, Ohio

But I want VALUE of that selected ITEM like: NJ, NY, OH

Share Improve this question edited May 27, 2015 at 22:11 amphetamachine 30.6k12 gold badges67 silver badges74 bronze badges asked May 27, 2015 at 21:59 MaddyMaddy 9273 gold badges10 silver badges25 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 6

You can use buttonText option of multiselect.

http://jsfiddle/ejqngpn5/

$('#lstStates').multiselect({ 
    buttonText: function(options, select) {
        console.log(select[0].length);
        if (options.length === 0) {
            return 'None selected';
        }
        if (options.length === select[0].length) {
            return 'All selected ('+select[0].length+')';
        }
        else if (options.length >= 4) {
            return options.length + ' selected';
        }
        else {
            var labels = [];
            console.log(options);
            options.each(function() {
                labels.push($(this).val());
            });
            return labels.join(', ') + '';
        }
    }

});

Use buttonText option of multiSelect Plugin. The Parameter options give you all the option you select. Then format your buttonText value as you want.

Script

$(function () {
   $('#lstStates').multiselect({
      buttonText: function(options){
         if (options.length === 0) {
            return 'No option selected ...';
         }

         var labels = [];
         options.each(function() {
           if ($(this).attr('value') !== undefined) {
               labels.push($(this).attr('value'));
           } 
         });
        return labels.join(', ');  
     }
  }); 
});

Take a look at the fiddle: http://jsfiddle/74b5pkpv/

发布评论

评论列表(0)

  1. 暂无评论