javascript 更改 jquery ui 进度条的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6421015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 20:36:41  来源:igfitidea点击:

changing the values of jquery ui progress bar

javascriptjqueryjquery-ui

提问by hilarl

i am trying to change the values of the progress bar widget to accept a json string i am getting which is something like:

我正在尝试更改进度条小部件的值以接受我收到的 json 字符串,类似于:

{
  'totalDays' : 31,
  'daysTaken' : 20
}

so i want the 'totalDays' to be the total value of the progress bar (total length) and the 'daysTaken' to fill the progress bar.

所以我希望 'totalDays' 是进度条的总值(总长度)和 'daysTaken' 来填充进度条。

according to the default docs, only the filled value is possible to change:

根据默认文档,只能更改填充值:

$(document).ready(function() {
  $("#progressbar").progressbar({ value: 37 });
});

回答by Matt Ball

There is a separate method to set the value after init.

在 init 之后有一个单独的方法来设置值。

var obj = {totalDays: 31, daysTaken: 20};
$("#progressbar").progressbar('value', obj.daysTaken/obj.totalDays * 100);

There is no configurable max value, but it's really not necessary since it is easy normalize values.

没有可配置的最大值,但实际上没有必要,因为它很容易标准化值。

http://jqueryui.com/demos/progressbar/

http://jqueryui.com/demos/progressbar/

回答by Shrikant Sharat

This is how you set the value of jquery-ui's progress bar

这就是你如何设置 jquery-ui 的进度条的值

$( ".selector" ).progressbar( "option", "value", 37 );

Source, the documentation at http://jqueryui.com/demos/progressbar/#option-value

来源,http://jqueryui.com/demos/progressbar/#option-value 上的文档