input框不允许手工输入,只允许设定好的值

<input type="number" id="inputValue" value="10" min="10" max="200" step="10" onkeydown="return false" onchange="updatePrice">

这里重要的是onkeydown="return false" 这个参数即可实现,这样每次只能10,20,这样增加,最大不超过200

<script>
    function updatePrice(productId, basePrice) {
        var inputValue = document.getElementById("inputValue_" + productId).value;
        var productPrice = document.getElementById("price_" + productId);
        var price = basePrice * (inputValue / 10);
        productPrice.innerHTML = "¥" + price.toFixed(2);
    }
</script>

 

 
posted @ 2024-02-02 15:20  super_ip  阅读(27)  评论(0编辑  收藏  举报