LiJun
2018-11-12 bd432a43162a6c9bb4b2fa0b11b07fd86af531c8
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// 生成特定的select列表
function createLayuiSelect(ele, list) {
    // 清空内容
    ele.text('');
    // 遍历list结果集生成下拉
    for(var i=0; i<list.length; i++) {
        var _list = list[i];
        var option = $('<option></option>');    // option元素
        // 设置option的文本/属性值/data值
        option.text(_list.txt);
        option.val(_list.val);
        option.attr('selected', _list.selected);
        option.data('data', _list.data);
        Object.keys(_list.attr).forEach(function(key){
            var val = _list.attr[key];
            option.attr(key, val);
        });
        ele.append(option);
    }
}
 
// 构造生成select列表的对象数组
function getLayuiSelect(txt, val, attr, data, isSelected) {
    var obj = {
        val: '',
        txt: '',
        attr: {},
        data: {}
    };
    
    // 设置内容的值
    obj.val = val;        // option的value值
    obj.txt = txt;        // option的文本值    
    obj.attr = attr;    // option的自定义的属性
    obj.data = data;    // option的data值
    obj.selected = isSelected?true:false;
    
    // 返回构造的对象
    return obj;
}
 
//格式化时间
Date.prototype.format =function(format)
{
    var o = {
    "M+" : this.getMonth()+1, //month
    "d+" : this.getDate(),    //day
    "h+" : this.getHours(),   //hour
    "m+" : this.getMinutes(), //minute
    "s+" : this.getSeconds(), //second
    "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
    "S" : this.getMilliseconds() //millisecond
    };
    if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
    (this.getFullYear()+"").substr(4- RegExp.$1.length));
    for(var k in o)if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,
    RegExp.$1.length==1? o[k] :
    ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
};