javascript and class class=input-range doesn't

2019-08-07 17:34发布

问题:

I am having an issue with some simple javascript not working in ie. My code is here:

<script>
function test(){
var myDivElem = document.getElementById("mydiv");
var sizerange= document.getElementById("sizeID");
myDivElem.innerHTML = sizerange.value;
}
</script>

<div>
<p>

<form action="url-link-here" method="post">

<span id="mydiv">100</span>

<input class="input-range" id="sizeID" oninput="test()" type="range" name="size" value="100" min="5" max="250" step ="5">

It works just fine in all other browsers.

回答1:

Use onchange instead of oninput. Worked in IE11

function test() {
    var myDivElem = document.getElementById("mydiv");
    var sizerange = document.getElementById("sizeID");
    myDivElem.innerHTML = sizerange.value;
  }
<form action="url-link-here" method="post">

  <span id="mydiv">100</span>

  <input class="input-range" id="sizeID" oninput="test()" onchange="test()" type="range" name="size" value="100" min="5" max="250" step="5">
</form>