fuchengshen
2022-07-15 e1186e0c9c1a7a47454b73f9cddcf733dce30b32
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
$.fn.range = function (cfg) {
    cfg = cfg || {};
 
    var $input = $(this);
 
    if (cfg.hasOwnProperty('min'))
        $input.attr('min', cfg.min);
 
    if (cfg.hasOwnProperty('max'))
        $input.attr('max', cfg.max);
 
    if (cfg.hasOwnProperty('step'))
        $input.attr('step', cfg.step);
 
    if (cfg.hasOwnProperty('value'))
        $input.val(cfg.value);
 
    function changeHandler(e) {
        var max = Number($input.attr('max'));
        var min = Number($input.attr('min'));
 
        var thisval = Number($input.val());
 
        var bfb = Math.floor((thisval - min) * 100 / (max - min));
        $input.css('background-size', bfb + '% 100%');
        $input.attr('title', thisval);
 
        if (e && cfg.hasOwnProperty('onChange') && e.type !== "change")//IE下去掉  e.type !== "change"
            cfg.onChange(thisval, bfb);
 
        return $input;
    }
 
 
    $input.change(changeHandler);
    $input.on('input propertychange', changeHandler);
 
    changeHandler();
 
    return this;
};