【发布时间】:2012-08-14 06:56:02
【问题描述】:
我的代码旨在通过计算百分比并将其作为 style.width 传递来设置进度条的宽度。我是新手,请为错误的代码道歉:
jQuery
$(document).ready(function() {
var width=(1/5*100);
$('#progress_bar').css('width','=width + "%"');
});
HTML
<div id="progress_bar" style="height:1em; background:red; display:block;"></div>
有空的人可以帮我让它工作并告诉我哪里出了问题,以便我从中吸取教训吗?
【问题讨论】:
-
为什么要在jQuery中计算?您可以像这样直接使用 css:#progress_bar{ width: 20% }
-
@HarshithJ.V.当页面丢弃一系列资产时,进度条会显示动画。随着它的进展,进展随着var宽度的变化而增加,即。 (1/5*100)、(1/4*100)、(1/3*100)等