jQuery:如何遍历在textarea中键入的文本的每个换行符? [英] jquery: how do you loop through each newline of text typed inside a textarea?

查看:510
本文介绍了jQuery:如何遍历在textarea中键入的文本的每个换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<textarea>内说,我在每一行中输入一堆关键字.

lets say inside a <textarea>, i type in a bunch of keywords on each new line.

keyword1
keyword2
keyword3
...




$('textarea[name=sometextarea]').val().split('\n').each(function(e){
alert($(this));                 
});

推荐答案

该数组对象没有任何each方法.在循环字符串而不是元素时,请使用jQuery.each方法(而不是jQuery().each方法):

The array object doesn't have any each method. As you are looping strings and not elements, use the jQuery.each method (instead of the jQuery().each method):

var lines = $('textarea[name=sometextarea]').val().split('\n');
$.each(lines, function(){
  alert(this);
});

这篇关于jQuery:如何遍历在textarea中键入的文本的每个换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆