/*
ele: id
size: 16、22 默认22
slabel: checkbox前描述信息
elabel: checkbox后描述信息
labelWidth: 文字区域宽度
onChange: '触发checkbox回调函数'
*/
define(function () {
function checkBox(config) {
this.ele = config.ele;
this.size = config.size || 16;
this.slabel = config.slabel;
this.elabel = config.elabel;
this.labelWidth = config.labelWidth || 'auto';
this.ele_cb = config.ele + '-cb';
this.onChange = config.onChange;
this.onInit();
}
checkBox.prototype.onInit = function () {
var html = '
';
if (this.slabel) {
html += '
'
}
html += '
'
if (this.elabel) {
html += '
'
}
html += '
'
$('#' + this.ele).addClass('fa-cb-container').html(html)
if (this.onChange && typeof this.onChange == 'function') {
var _self = this;
$('#' + this.ele_cb).change(function () {
_self.onChange()
})
}
};
checkBox.prototype.getValue = function () {
return $('#' + this.ele_cb)[0].checked
};
checkBox.prototype.setValue = function (val) {
$('#' + this.ele_cb).prop('checked', val);
};
return checkBox
})