【问题标题】:Textbox Width Manipulation - Not working on mobile文本框宽度操作 - 不适用于移动设备
【发布时间】:2018-05-07 22:49:40
【问题描述】:

我想限制下面的空文本框和文本区域框中的空间 代码在移动设备中无法运行,它在桌面上运行,请检查并提供帮助

<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script>
    $(document).ready(function() {
        $("input[type=text],textarea").keypress(function(e) {
            if(e.which === 32 && !this.value.length) {
                return e.which !== 32;
            }
        });
    });
    </script>
</head>
<input type="text" maxlength='25'>
<textarea></textarea>

</html>

【问题讨论】:

    标签: javascript jquery html css


    【解决方案1】:

    您的选择器将取消页面上所有文本框文本区域中的空格键。你确定吗?

    如果你是,那么你可以使用keydown事件和event.preventDefault()取消空格键。

    $("input[type=text],textarea").keydown(function(event) {
      if (event.keyCode == '32') {
        event.preventDefault();
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2011-08-28
      • 2021-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 2016-11-02
      • 2023-03-23
      相关资源
      最近更新 更多