【问题标题】:Hide HTML5 number input’s spin box but accepts alphanumeric characters隐藏 HTML5 数字输入的旋转框,但接受字母数字字符
【发布时间】:2014-09-13 03:13:45
【问题描述】:

我已从输入 type="number" 中隐藏了旋转框箭头,但数量限制已不起作用。因此,数字框现在接受字母数字字符。

当我能够隐藏微调器箭头时,我使用了此代码:

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    /* display: none; <- Crashes Chrome on hover */
    -webkit-appearance: none;
    margin: 0; /* <-- Apparently some margin are still there even though it's hidden */
}

嗨@BenM!感谢您编辑我的问题。现在,感谢使用 javascript @FakeRainBrigand 的想法,但它对我不起作用。

这对我有用。我正在使用 MVCRazor

` 功能按键(e){ var unicode = e.keyCode ? e.keyCode : e.charCode

    if (unicode == 8) {
            return;
        };

    if (unicode == 37 || unicode == 39 || unicode == 38 || unicode == 40 || unicode == 27) {
        return;
        }
        else {

        };

    if (unicode == 13) {
            e.preventDefault();
        };

    if ($.isNumeric(String.fromCharCode(unicode)) == false) {
            e.preventDefault();
        };
    }

`

【问题讨论】:

  • 我在 MVC masterpage @RenderSection("NumValidation", required: false) 中使用了 Razor
  • 我把这些小码放在输入元素上:onkeypress="keeypress(event)" onchange="keeypress(event)"

标签: css html jquery-mobile


【解决方案1】:

您需要使用 JavaScript 等客户端脚本。最好use jquery validation 限制表单输入中的字母数字字符。

【讨论】:

  • 通常我会同意你的观点,但这个答案也指定了 what
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-11
  • 1970-01-01
  • 2015-03-09
  • 2018-12-17
相关资源
最近更新 更多