获取Jquery进度条的值

时间:2013-02-12 18:02:23

标签: jquery html

我希望找到进度条的值,这样我就可以在每一步中增加一个百分比,但无论我尝试它还是说它是未定义的,或者在实例化对象之前无法调用该方法。 / p>

我尝试过的事情:

 alert($('progressbar:first').prop('progress-label')); 

 progressbarValue = progressbar.find( ".progress-label" ).val();

HTML

<div id="progressbar"><div class="progress-label">Form Process</div></div>

if(condition == true) {

    progressbar = $( "#progressbar" );
    progressbarValue = progressbar.find( ".ui-progressbar-value" );
    progressLabel = $( ".progress-label" );


    var size = parseInt($("#fieldWrapper .step").size(),10);
    var progress = 100/size ; 

 alert($('progressbar:first').prop('progress-label')); 
  progressbar.progressbar({
      value: progress,
      change: function() {
        progressLabel.text( progressbar.progressbar( "value" ) + "%" );

      },
      complete: function() {
        progressLabel.text( "Complete!" );
      }
    });

        progressbarValue.css({
          "background": '#' + Math.floor( Math.random() * 16777215 ).toString( 16 )
        });

}

1 个答案:

答案 0 :(得分:5)

尝试使用进度条小部件的值方法。

$("#progressbar").progressbar("value");

http://api.jqueryui.com/progressbar/#method-value

注意,您必须先前已经启动了进度条才能获得它的值。否则,元素还不是进度条。

演示:http://jsfiddle.net/3sbTw/

相关问题