将用户限制为最大限制以在文本区域中输入文本 [英] Restrict the user to a max limit to enter text in a textarea
问题描述
我限制用户在文本区域中输入字符的最大限制(40个字符).
在textarea的onKeyUp事件上的JS函数下面调用此函数.
但是当我复制粘贴的内容超过40个字符时,直到我在textarea上进行键入/下移之前,都不要获取popup-up(Alert).
粘贴到textarea后是否可以在没有键盘上/下键的情况下获得警报?
提前谢谢!
I am restricting the user to enter a max limit(40Char) of characters in a text area.
Calling this below JS function on onKeyUp event of textarea.
But when i copy paste a content which is more than 40chars, not gettinng pop-up(Alert) until i do a keyup/down on the textarea.
Is there a way to get alert without keyup/down after pasting into textarea?
Thanks in advance!
function checkMaxLength(textBox, e, maxLength) {
if (textBox.value.length > maxLength - 1) {
alert("* You have reached max limit ");
textBox.value = textBox.value.substr(0, maxLength);
} else {
alert(maxLength - textBox.value.length + " characters remaining");
}
我尝试了以下方法,它在IE,Safari,Chrome上运行正常,但在Mozilla Firefox上却无法运行,对此有何想法?
I have tried the below approach, It is working fine on IE,Safari,Chrome but not working on Mozilla Firefox, Any thoughts on this?
<HTML><head></head><body>
<form name="myForm">
Text: <input type="text" name="myText"
önKeyUp = "fncKeyLength(this);">
</form>
<script>
function fncKeyLength(text){
if (window.event.ctrlKey){
if (window.event.keyCode == 86) {
alert("<br />The string is this long: " + text.length);
}
}}
</script></body></HTML>
推荐答案
检查此网址
复制粘贴 [
check this url
copy paste[^]
这篇关于将用户限制为最大限制以在文本区域中输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!