本文介绍了如何在JQuery Spinner中添加后缀文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将后缀添加到jQuery Spinner(jquery.ui.spinner)中.例如:10.02%.

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

我尝试通过 jquery.ui.spinner [在选项"部分下"进行跟踪,但是对我不起作用.

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: "%",
}); 

提前了解帮助.

谢谢.

推荐答案

遇到了同样的问题.

使用jQuery UI的小部件工厂,这非常容易:

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 });

演示: http://jsfiddle.net/aAHuT/

如果要使用整数,则必须将'_parse'修改为使用parseInt():

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

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

时间微调器的jQuery UI示例对于提出此解决方案非常有帮助.

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

这篇关于如何在JQuery Spinner中添加后缀文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 03:34