Javascript DOM HTML Input Number step Property set

Introduction

Change the legal number intervals for a number field:

document.getElementById("myNumber").step = "5";

Click the button to change the value of the step attribute of the number field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Number://w  ww.  j av a2s.  c o m
<input type="number" id="myNumber" step="3">
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myNumber").step = "5";
  document.getElementById("demo").innerHTML = "The value of the step attribute was changed.";
}
</script>

</body>
</html>



PreviousNext

Related