Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
811 views
in Technique[技术] by (71.8m points)

plugins - How to add Suffix text in JQuery Spinner

Is it possible to add suffix into jQuery spinner (jquery.ui.spinner). e.g: 10.02%.

I tried following, from jquery.ui.spinner [under Option section], but it did not work for me.

$("#spinner").spinner({
    step: 0.01,
    numberformat: "n",
    suffix: "%",
}); 

Appreciate the help in advance.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have had the same problem.

With jQuery UI's widget factory it is quite easy:

$.widget( "ui.pcntspinner", $.ui.spinner, {
    _format: function(value) { return value + '%'; },

    _parse: function(value) { return parseFloat(value); }
});

$("#spinner").pcntspinner({ 
    min: 0,
    max: 100,
    step: .01 });

Demo: http://jsfiddle.net/aAHuT/

If integers are to be used '_parse' has to be adapted to use parseInt():

_parse: function(value) { return parseInt(value); }

The jQuery UI example for the Time Spinner has been very helpful for coming up with this solution.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...