根据特定输入触发事件到textarea [英] Trigger event based on specific inputs into a textarea
本文介绍了根据特定输入触发事件到textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
导致这种情况的原因或者是某人按下了一个按钮来触发一个JS事件。返回键四次,一个人粘贴包含四个换行符的文本,或者删除一些导致连续四次换行符的内容(即段落)。
谢谢
p>解决方案
请尝试以下解决方案:
document.getElementById(textArea)。addEventListener(keyup,function(event){
var numberOfLineBreaks =(this.value.match(/ \ / g)|| [])。length;
if(numberOfLineBreaks === 4){
console.log(4连续行!);
}
});
I'm trying to trigger a JS event when there are four consecutive linebreaks inside of a textarea.
The situation causing this would either be that a person presses the RETURN key four times, a person pastes text that contains four line breaks, or they delete some content (ie a paragraph) that results in four consecutive linebreaks.
Thanks
解决方案
Try below solution:
document.getElementById("textArea").addEventListener("keyup", function(event) {
var numberOfLineBreaks = (this.value.match(/\n/g)||[]).length;
if (numberOfLineBreaks === 4) {
console.log("4 consecutive Lines!");
}
});
这篇关于根据特定输入触发事件到textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文