最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - set progress bar value from variable - Stack Overflow

programmeradmin3浏览0评论

I have a variable which updates based on percent file downloaded. How can I get this variable to update a progress bar?

var percent = (len / res.headers['content-length']) * 100;

I have tried this to no avail:

<progress class="progress"></progress>

$('.progress').val = percent;

I have a variable which updates based on percent file downloaded. How can I get this variable to update a progress bar?

var percent = (len / res.headers['content-length']) * 100;

I have tried this to no avail:

<progress class="progress"></progress>

$('.progress').val = percent;
Share Improve this question asked Oct 10, 2013 at 4:46 user2387226user2387226
Add a ment  | 

4 Answers 4

Reset to default 9

You need to set the value using the setter of .val(newValue). val just gives you the function reference, you are just resetting it to the value of variable percent, not really assigning it as value.

Change

 $('.progress').val = percent;

to

 $('.progress').val(percent);

You could also do $('.progress')[0].value = percent. probably that is what you had in mind. But val in jquery is used as a function, (more like getter, setter kind of functionality).

Also do remember that progress element takes value ranging from 0.0 to 1.0 or the value of the max attribute (if present).

Pass value in val() like,

$('.progress').val(percent);

HTML

<progress class="progress" value="10" max="100"></progress>

Fiddle

you are giving in wrong way

give like this

 $('.progress').val(percent);

see val()

Your method is wrong in jquery you need to write like this:

$('.progress').val(percent);
发布评论

评论列表(0)

  1. 暂无评论