简体   繁体   中英

How to update the text indicator to show progress from the progress bar?

I have this HTML:

<head>
  <script language=JavaScript></script> 
</head>
<body>
  <progress value="0" max="100" id=p1></progress>
  <input type=button value='Increse' onClick='incr();'>
  <div id="numValue">0%</div>
</body>
</html>

with this source code:

<script language=JavaScript> 
  <!--
  function incr() { 
    var v1=document.getElementById('p1').value;
    document.getElementById("p1").value= v1 + 5;
    var val = document.getElementById("numValue");
  }
  //-->
</script>

I don't know how to update the numValue text indicator to show me the progress value as the progress bar completes.

var val = document.getElementById("numValue");之后添加以下代码var val = document.getElementById("numValue");

val.innerHTML = v1 + 5+'%'

 function incr() { 
   var v1=document.getElementById('p1').value;
   document.getElementById("p1").value= v1 + 5;
   var val = document.getElementById("numValue");
   document.getElementById("numValue").innerHTML = (v1 + 5) + "%"

}  

but it's better to write like this :

 function incr() { 
  var progress = document.getElementById('p1');
  var numValue = document.getElementById("numValue")
  var newValue = progress.value + 5;
  progress.value = newValue;
  numValue.innerHTML = newValue + "%"

}

why you do not use jquery?

with jquery you can do this :

$(document).ready (function (){
  function incr ()
  {
     $('#numValue').val ($('#p1').val ()+5+'%');
 }
     $('input [type="button"]').click (function (){incr ();});
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM