简体   繁体   English

如何根据条件更改输入类型=“范围” =>步进值?

[英]How to change input type=“range” =>step value based on condition ?

How to change input type="range" =>step value based on condition ? 如何根据条件更改输入type =“ range” => step值?

like i want :Difference: 200 250 350 450 all the way to 1150, 1200 就像我想要的那样:差异:200250350450一直到1150、1200

<input id="years" type="range" value="200" min="200" max="1200" />

First value is 200..then its increase by 50...after that its increase by 100...(its look like : 250..350...1150...) 第一个值是200 ..然后增加了50 ...之后增加了100 ...(它看起来像是:250..350 ... 1150 ...)

Look What I have tried...But not getting proper output 看我尝试了什么...但是没有得到正确的输出

    <html>
    <head>
        <script  src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
        <script type="text/javascript">

            $(function() {

                $('#years').on('input change', function() {

                    var
                        element = $('#years'),
                        value = element.val(),
                        step;

                    /* 
                        Map your rules 
                    */
                    if (value <=250) {


                        step = 50;
                    }
                    else {

                        step = 100;   
                    }

                    element.attr('step', step);

                    $('#value').text(value);
                    $('#step').text(step);
                });
            });

        </script>
    </head>
    <body>
        <div>
            Current value: <span id="value"></span>
        </div>
        <div>
            Current step: <span id="step"></span>
        </div>
        <div style="width:500px">
            <input id="years" type="range" value="200" min="200" max="1200" />
        </div>
    </body>
    </html>

            <input id="years" type="range" value="200" min="200" max="1200" /> 

这个答案应该正是您要寻找的答案: html输入范围步骤作为值的数组 (您必须根据需要调整值和步骤)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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