如何逐行读取文本区域HTML标记 [英] How to read line by line of a text area HTML tag
本文介绍了如何逐行读取文本区域HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本区域,每行包含如下的整数值
I have a text area where each line contains Integer value like follows
1234
4321
123445
我想检查用户是否确实输入了有效值,而不是一些有趣的值,如下所示
I want to check if the user has really enetered valid values and not some funny values like follows
1234,
987l;
为此,我需要逐行阅读文本区域并验证。
如何使用javascript逐行读取文本区域?
For that I need to read line by line of text area and validate that. How can i read line by line of a text area using javascript?
推荐答案
试试这个。
var lines = $('textarea').val().split('\n');
for(var i = 0;i < lines.length;i++){
//code here using lines[i] which will give you each line
}
这篇关于如何逐行读取文本区域HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文