1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| require(['jquery','moye/BoxGroup'], function ($, BoxGroup) { new BoxGroup({ main: document.getElementById('checkbox2'), icons: false, activeClass: 'ui-boxgroup-item-checked', datasource: [ {value: 0, name: '不限'}, {value: 1, name: '中关村-上地'}, {value: 2, name: '亚运村'}, {value: 3, name: '北京南站商圈超长'} ], value: [1], getItemHTML: function (state, item) {
var classNames = this.helper.getPartClasses('item'); var index = $.inArray(item, this.datasource);
if (state) { classNames.push(this.activeClass); }
if (index === 0) { classNames.push('first'); } else if (index === this.datasource.length - 1) { classNames.push('last'); }
return '' + '<label class="' + classNames.join(' ') + '" data-role="boxgroup-item">' + '<input type="' + this.boxType + '" value="' + item.value + '">' + item.name + '</label>';
} }) .render() .on('change', function(e) { $('#values').html(this.getValue().join(',')); }); });
|