2017-10-19 89 views
3

在我的asp.net web應用程序我使用的是
jQuery函數jQuery函數不工作的文本區域

$(document).ready(function() { 
     $('input').on('input', function() { 
      var c = this.selectionStart, 
       r = /[^[email protected]&%./() +-]/gi, 
       v = $(this).val(); 
      if (r.test(v)) { 
       $(this).val(v.replace(r, '')); 
       c--; 
      } 
      this.setSelectionRange(c, c); 
     }); 
    }); 

功能適用於文本框的預期,但它不是工作多限制用戶輸入的字符文本框。
[設計例如:<asp:TextBox ID="txtAddAdds" class="form-control" placeholder="Default Input" autocomplete="off" runat="server" TextMode="MultiLine"></asp:TextBox]

爲什麼此功能對多行文本框沒有影響。
Somebuddy請幫助我..

+4

因爲在HTML它不是'input',而是一個'textarea'。那麼你的選擇器不起作用。 – VDWWD

+0

Asp.Net經典的html標記呈現時。你可以看看這個文本框 –

回答

1

你的功能僅針對inputs,你需要的目標textareas太:

$(document).ready(function() { 
    $('input, textarea').on('input', function() { 
     var c = this.selectionStart, 
      r = /[^[email protected]&%./() +-]/gi, 
      v = $(this).val(); 
     if (r.test(v)) { 
      $(this).val(v.replace(r, '')); 
      c--; 
     } 
     this.setSelectionRange(c, c); 
    }); 
});