简体   繁体   English

jQuery进度栏未显示

[英]jquery progress bar not showing up

I have a for loop that I need to loop through and create progress bars with jquery. 我有一个for循环,我需要遍历并使用jquery创建进度条。 For some reason, the progress bars just show up empty, with no shaded area and I can't seem to figure out why this could be. 出于某种原因,进度条只是显示为空,没有阴影区域,我似乎无法弄清楚为什么会这样。 I've created a jsfiddle to show what I'm currently dealing with. 我创建了一个jsfiddle来显示我当前正在处理的内容。 Any ideas would be greatly appreciated! 任何想法将不胜感激!

HTML: HTML:

<div class="panel panel-default">
  <table class="table" border=1>
    <tbody>

      <tr>
        <td><strong>ProgressBars:</strong>

        </td>
        <td>
          <div id="progress"></div>
        </td>
      </tr>
    </tbody>
  </table>
</div>

Javascript: Javascript:

for (i = 0; i < 7; i++) {
  var taskDiv = '<div><table border=1 class="table table-condensed">';
  var progress = 47;

  taskDiv += ('<tr><td colspan="3"><div id="progressContainer' + i + '" class="progressContainer"><div id="progressbar' + i + '" class="progressbar"></div></div></td></tr>');

  setProgress(progress, i);

  taskDiv += ('</table></div>');
  $(taskDiv).appendTo('#progress');
}

function setProgress(progress, uid) {
  var progressBarWidth = $("#progressContainer" + uid).width() * (progress / 100);
  $("#progressbar" + uid).width(progressBarWidth).html(progress + "% ");
}

CSS: CSS:

/* Progress bar */

.progressbar {
  color: #fff;
  text-align: right;
  height: 25px;
  width: 0%;
  background-color: #337ab7;
  border-radius: 3px;
}

.progressContainer {
  width: 300px;
  border: 1px solid #ddd;
  border-radius: 5px;
  overflow: hidden;
  display: inline-block;
  margin: 0px 10px 5px 5px;
  vertical-align: top;
}

You just need to set the progress AFTER you append the HTML of the progress bars. 您只需要在添加进度条的HTML之后设置进度。 Like this: 像这样:

taskDiv += ('</table></div>');
$(taskDiv).appendTo('#progress');

setProgress(progress, i);

jsfiddle jsfiddle

Otherwise, when you call the setProgress function there's no $("#progressbar") elements and that function does nothing. 否则,当您调用setProgress函数时,没有$("#progressbar")元素,并且该函数不执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM