【问题标题】:Input type number should start again from min value with up arrow and max value with down arrow输入类型编号应从带有向上箭头的最小值和带有向下箭头的最大值重新开始
【发布时间】:2017-12-18 02:57:29
【问题描述】:

我有数字输入,

<input type="number" name="start" id="start" value="0" min="0" max="24" />

所以,我想要功能,比如当我单击向上箭头直到最大值(此处为 24)达到之后,它应该从 0 重新开始,并且当达到限制时相同,直到最小值(此处为 0)带有向下箭头,之后它应该从 24 开始。

同样应该使用 keyup 和 keydown 箭头。

任何帮助将不胜感激!

【问题讨论】:

    标签: javascript php jquery html input


    【解决方案1】:

    类似的东西

    function myFunction(){
    if(document.getElementById("start").value == 25){
     document.getElementById("start").value = 0;
    }
    }
    &lt;input type="number" name="start" id="start" value="0" min="0" max="25" onchange="myFunction()" /&gt;

    如果你想在数字为 0 时做同样的事情,请使用以下代码:

    function myFunction(){
    if(document.getElementById("start").value == 25){
     document.getElementById("start").value = 0;
    }
    if(document.getElementById("start").value == -1){
     document.getElementById("start").value = 24;
    }
    }
    &lt;input type="number" name="start" id="start" value="0" min="-1" max="25" onchange="myFunction()" /&gt;

    【讨论】:

    • 但它不是用向下箭头单击反转值24&gt;23&gt;22...
    • 你的意思是当它从 0 到 24 时你想要它?
    • yes on downarrow press in 0 value it go with 24 again min value(0 here) with down arrow, after that it should start with 24.refer OP question
    • if(document.getElementById("start").value == 0){ document.getElementById("start").value = 24; }
    • 只需在函数内添加该行
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2016-07-30
    • 2019-12-18
    • 2021-08-13
    • 2012-09-13
    相关资源
    最近更新 更多