【发布时间】: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