且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript只允许数字粘贴

更新时间:2023-02-21 11:16:01

调用上的函数更改 Textbox事件,而不是 document.ready

Call the function onchange event of Textbox as, instead of document.ready:

HTML

<asp:TextBox ID="txt" runat="server" onchange="onlyNum()"></asp:TextBox>

JQuery

    function onlyNum() {
      var $this = $('#txt');
      $this.val($this.val().replace(/\D/g, ''));
    }