【问题标题】:simple progress bar using JQuery does not work使用 JQuery 的简单进度条不起作用
【发布时间】:2013-01-18 06:12:48
【问题描述】:

我是JavaScript的新手,我负责一个在线测验(html5代码),执行“startgame”功能需要很长时间(为100个问题构建html)。所以我添加了一个进度条,

   function startgame()
   {    
    var progress=0;
    for (index = 0; index < numberofquestions; index++) {
    progress=index+"%";
    $("#progress-bar").css("width",progress);
    ...
    }
    ...}

而progress-bar是html代码中一个div的id

<div id="progress-bar" style="width:0%; background:blue;opacity:1;height:25px;"/>`

当我跨过 for 循环时,它按预期工作(条的宽度正在增加),但是,如果我删除断点并运行,它根本不起作用(进度将保持在 0% 或点我停止调试) 我也试过了

document.getElementById("progress-bar").outerHTML='<div id="progress-bar"          style="width:'+progress+';background:blue;opacity:1; display:block; height:25px;"'+'/>';

替换 $("#progress-bar").css("宽度",progress); 但结果和以前一样

【问题讨论】:

  • " which takes long time to execute "startgame" function (construct the html for 100 questions" 您的首要任务应该是优化这 100 个问题的附加,因为它的数据量并不大,而且您需要一个进度条的时间不会太长

标签: javascript jquery html progress-bar


【解决方案1】:

numberofquestions.length 应该为您提供数组 numberofquestions 的整个长度。你错过了所有的代码,所以除此之外不能说..

【讨论】:

  • 我的困难是通过for循环的迭代来移动进度条,无论如何谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 1970-01-01
相关资源
最近更新 更多