简体   繁体   中英

stepUp(1) , stepDown(1) not working in IE

HTML5 stepUp(1) and stepDown(1) are not working in IE. Here is my code:

<div class = "col-sm-3">
    <div class = "waist">             
        <p class = "waist-measure" id="mens-bottom-waist">Waist</p>
        <a class = "waist-plus btn" onclick="waistPlus()">+</a>
        <a class = "waist-minus btn " onclick="waistMinus()">-</a>
    </div>
</div>

<script>
function waistPlus() {
    document.getElementById("waist").stepUp(1);
}
    function waistPlus() {
    document.getElementById("waist").stepDown(1);
}
</script>

The methods stepUp and stepDown are only defined on <input> elements with type="number" . The element with id="waist" in your document isn't of that type, so the methods don't work.

The methods stepUp and stepDowm are not supported by IE. You can achieve this by using this:

 var my_value = 1; function stepup(){ var cur_val = document.querySelector("#quantity").value; if(cur_val == 1 || cur_val > 1){ //Parse Current Value to Int my_value = (parseInt(cur_val) + 1); document.querySelector("#quantity").value = my_value; } } function stepdown(){ var cur_val = document.querySelector("#quantity").value; if(cur_val > 1){ //Parse Current Value to Int my_value = (parseInt(cur_val) - 1); document.querySelector("#quantity").value = my_value; } }
 <input type="number" id="quantity" autocomplete="off" step="1" value="1"/> <button type="button" onclick="stepup();">StepUp</button> <button type="button" onclick="stepdown();">StepDown</button>

Hope this will help

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