Установите "style = width:" с переменной

я использую

    <div class = "progress">
      <div class = "progress-bar bg-success" role = "progressbar"    style = "width:100%" th:attr = "aria-valuenow=${progress}" aria-valuemin = "0" aria-valuemax = "100">
      </div>
    </div>

Я хочу изменить style = "width: 100%" и использовать переменную, поступающую в контроллер, например, model.addAttribute ("percent", "100").

Как я могу это изменить?

Спасибо.

0
0
372
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

вам нужно работать с атрибутом aria-valuenow

$(function() {
  var current_progress = 0;
  var interval = setInterval(function() {
      current_progress += 10;
      $("#dynamic")
      .css("width", current_progress + "%")
      .attr("aria-valuenow", current_progress)
      .text(current_progress + "% Complete");
      if (current_progress >= 100)
          clearInterval(interval);
  }, 1000);
});
.progress {
  margin: 10px;
  width: 700px;
}
<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity = "sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin = "anonymous">
<script src = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity = "sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin = "anonymous"></script>

<h3>Dynamic Progress Bar</h3>
<p>Running progress bar from 0% to 100% in 10 seconds</p>
<div class = "progress">
  <div id = "dynamic" class = "progress-bar progress-bar-success progress-bar-striped active" role = "progressbar" aria-valuenow = "0" aria-valuemin = "0" aria-valuemax = "100" style = "width: 0%">
    <span id = "current-progress"></span>
  </div>
</div>

Другие вопросы по теме