Change Bootstrap progress bar dynamically

后端 未结 1 1968
误落风尘
误落风尘 2021-01-05 03:01

I have the following HTML code, using Bootstrap:

相关标签:
1条回答
  • 2021-01-05 03:35

    The code you use to update width is correct, but as @Brennan pointed out it has to run after the progress bar is rendered - e.g. by placing the script tag after the progress bar tag (fiddle) or by running it in the document ready handler (fiddle).

    The following is the minimal version which does what you tried (the fiddles emulate progress running from 0 to 100):

    $(function() {
         $("#progress-bar").css("width", "50%");
    });
    

    Another note on the code: along with the width of the progress bar you should update the aria-valuenow attribute which represents the current value of a range widget (here the progress bar) for the assistive technology browsers. In your sample you have aria-valuenow 45 but width 0, which is inconsistent.

    0 讨论(0)
提交回复
热议问题