【问题标题】:jQuery keyup , keypress stopped working on iOSjQuery keyup , keypress 在 iOS 上停止工作
【发布时间】:2021-12-08 00:00:51
【问题描述】:

我有一个函数只允许输入文本中的数字:

$('.NumberThousandSeprator').on('change click keyup input paste', (function (event) {
    $(this).val(function (index, value) {
        return value.replace(/(?!\.)\D/g, "").replace(/(?<=\..)\./g, "").replace(/(?<=\.\d\d)./g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    });
}));
<input type="text" class="NumberThousandSeprator"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

之前它在所有设备上都运行良好,但从昨天开始它在 iOS 上停止运行,而它仍在 Android 和 Windows 浏览器上运行。 有没有人有同样的问题?或者有人解决了这个问题吗?

【问题讨论】:

    标签: javascript jquery ios iphone


    【解决方案1】:

    你试过了吗

    确保在页面准备好后调用它

    $(function(){
    
    $('.NumberThousandSeprator').on('change click keyup input paste', (function (event) {
        $(this).val(function (index, value) {
            return value.replace(/(?!\.)\D/g, "").replace(/(?<=\..)\./g, "").replace(/(?<=\.\d\d)./g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        });
    }));
    
    });
    

    另一个建议是

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      • 1970-01-01
      • 2015-08-21
      • 2019-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      相关资源
      最近更新 更多