优化 checkbox 的 `title` 以向下兼容

pull/1201/head
贤心 2 years ago
parent 203b868bed
commit 7214a9a6cc

@ -618,12 +618,12 @@ layui.define(['lay', 'layer', 'util'], function(exports){
// 复选框/开关
,checkbox: function(elem){
var CLASS = {
checkbox: ['layui-form-checkbox', 'layui-form-checked', 'checkbox']
,_switch: ['layui-form-switch', 'layui-form-onswitch', 'switch']
"checkbox": ['layui-form-checkbox', 'layui-form-checked', 'checkbox'],
"switch": ['layui-form-switch', 'layui-form-onswitch', 'switch']
}
,checks = elem || elemForm.find('input[type=checkbox]')
var checks = elem || elemForm.find('input[type=checkbox]');
,events = function(reElem, RE_CLASS){
var events = function(reElem, RE_CLASS){
var check = $(this);
// 勾选
@ -647,20 +647,19 @@ layui.define(['lay', 'layer', 'util'], function(exports){
,othis: reElem
});
});
}
};
// 遍历复选框
checks.each(function(index, check){
var othis = $(this);
var skin = othis.attr('lay-skin') || 'primary';
check.title || (check.title = othis.attr('lay-text') || ''); // 向下兼容将以前设置在lay-text的值赋给title
var title = (check.title.replace(/\s/g, '') || '').split('|');
var title = (function(title){
// 向下兼容 lay-text 属性
return title || othis.attr('lay-text') || '';
})(check.title).replace(/\s/g, '').split('|');
var disabled = this.disabled;
if(skin === 'switch') {
skin = '_'+ skin;
} else if (skin !== 'tag') {
skin = 'primary';
}
if(skin !== 'tag') skin = 'primary'; // 若非内置风格,则强制为默认风格
var RE_CLASS = CLASS[skin] || CLASS.checkbox;
if(typeof othis.attr('lay-ignore') === 'string') return othis.show();

Loading…
Cancel
Save