How to add a value suffix in jQuery.knob

后端 未结 4 1111
滥情空心
滥情空心 2021-02-03 14:00

I have problem with jQuery.knob I need to add a Sufixx to the value in the knob.

For Example: i need a Sufix $ after the value, i just

4条回答
  •  清歌不尽
    2021-02-03 14:34

    Your code actually not work because 51$ is not a valid int number, so it display 0.

    Since that the plugin actually not implement any prefix/suffix feature, I built a little hack so in the draw callback it:

    • get the position of the input element on which knob is applied
    • build a span and append it after the input, and copied the same styles of the input
    • move the position of the new element to let it appear as a suffix

    Request: https://github.com/aterrien/jQuery-Knob/issues/65

    Code:

        'draw': function () {
            if ($(this.i).siblings(".kb-suffix").length > 0) return
            var pos1 = parseInt($(this.i).css("marginLeft").replace('px', ''));
            var pos2 = parseInt($(this.i).css("marginTop").replace('px', ''));
            var $elem = $("$").attr("style", $(this.i).attr("style")).addClass("kb-suffix");
            $elem.insertAfter(this.i).css({
                marginLeft: (pos1 + 20) + "px",
                marginTop: (pos2 + 3) + "px",
                zIndex: -10
        });
    

    Demo: http://jsfiddle.net/IrvinDominin/ngX5p/

提交回复
热议问题