0

目前:

  1. 点击“开始下载”按钮
  2. 显示“文件下载”框
  3. 下载开始
  4. 进度指示器开始并运行到 100%
  5. 方框表示“完成”

我未能成功修改代码以执行以下操作:

  1. 点击“开始下载”按钮
  2. 显示“文件下载”框
  3. 文件 1 下载开始
  4. 进度指示器显示“文件 1 正在下载”,然后开始并运行到 100%
  5. 文件 2 下载开始
  6. 进度指示器显示“文件 2 正在下载”,然后开始并运行到 100%
  7. 文件 3 下载开始
  8. 进度指示器显示“文件 3 正在下载”,然后开始并运行到 100%
  9. 方框表示“完成”

我使用的代码位于以下 URL:https ://jqueryui.com/progressbar/#download

  $(function() {
var progressTimer,
  progressbar = $( "#progressbar" ),
  progressLabel = $( ".progress-label" ),
  dialogButtons = [{
    text: "Cancel Download",
    click: closeDownload
  }],
  dialog = $( "#dialog" ).dialog({
    autoOpen: false,
    closeOnEscape: false,
    resizable: false,
    buttons: dialogButtons,
    open: function() {
      progressTimer = setTimeout( progress, 2000 );
    },
    beforeClose: function() {
      downloadButton.button( "option", {
        disabled: false,
        label: "Start Download"
      });
    }
  }),
  downloadButton = $( "#downloadButton" )
    .button()
    .on( "click", function() {
      $( this ).button( "option", {
        disabled: true,
        label: "Downloading..."
      });
      dialog.dialog( "open" );
    });

progressbar.progressbar({
  value: false,
  change: function() {
    progressLabel.text( "Current Progress: " + progressbar.progressbar( "value" ) + "%" );
  },
  complete: function() {
    progressLabel.text( "Complete!" );
    dialog.dialog( "option", "buttons", [{
      text: "Close",
      click: closeDownload
    }]);
    $(".ui-dialog button").last().focus();
  }
});

function progress() {
  var val = progressbar.progressbar( "value" ) || 0;

  progressbar.progressbar( "value", val + Math.floor( Math.random() * 3 ) );

  if ( val <= 99 ) {
    progressTimer = setTimeout( progress, 50 );
  }
}

function closeDownload() {
  clearTimeout( progressTimer );
  dialog
    .dialog( "option", "buttons", dialogButtons )
    .dialog( "close" );
  progressbar.progressbar( "value", false );
  progressLabel
    .text( "Starting download..." );
  downloadButton.focus();
}

});

4

0 回答 0