Progress bar width

。_饼干妹妹 提交于 2019-12-11 09:18:34

问题


My code is designed to set the width of my progress bar by calculating the percentage and passing it as a style.width. I am a novice, so apologise for the bad code:

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>

Could someone with a second to spare please help me to get it working and show me where I've gone wrong so I can learn from this?

http://jsfiddle.net/SyxAM/


回答1:


The string '=width + "%"' can't be the value of a css parameter.

You probably wanted

 $('#progress_bar').css('width', width + "%");



回答2:


this will solve your problem

var width=(1/5*100);

$('#progress_bar').css('width',width + "%");




回答3:


Your variable appending was wrong.It should be like this;

$(document).ready(function() {
var width=(1/5*100);
$('#progress_bar').css('width', width + "%");
});

You can see here http://jsfiddle.net/SyxAM/2/



来源:https://stackoverflow.com/questions/11947220/progress-bar-width

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!