[英]Remove characters in textarea at the time of pasting text
Whenever i paste text in textarea , it should strip the character like <,>,@ etc. i try in JQuery 每当我在textarea中粘贴文本时,它都应该剥离<,>,@等字符。我在JQuery中尝试
$('input').on('paste', function () { var element = this; setTimeout(function () { var text = $(element).val(); // do something with text }, 100); });
$('input').on('paste', function () { var element = this; setTimeout(function () { var text = $(element).val(); text.replace('<', '') ); }, 100); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <textarea id="test" name="test" style="height:300px; width:400px"></textarea>
You are using input
element selector which matches only elements with tagname as input
like <input type="..." />
, instead of textarea
so 您正在使用input
元素选择器 ,该选择器仅匹配具有标记名作为input
元素,例如<input type="..." />
,而不是textarea
,
$('textarea').on('paste', function() { var $el = $(this); setTimeout(function() { $el.val(function(i, val) { return val.replace(/[<>@]/g, '') }) }) });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <textarea id="test" name="test" style="height:300px; width:400px"></textarea>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.