开发者

textarea into array javascript

myList contains the following values:

value1

value2

value3

function showArray() {
  var txt = $("#myList").text();
  var textread = txt.split('\n');

  var msg = "";
  for (var i = 0; i < textread .length; i++) {
    msg += i + ": " + textread [i] + "\n";
  }
  alert(msg);
}

my alert gives me the following:

0:value1

value2

value3

It`开发者_如何学Pythons not what I wanted and expecting, I was expecting something like:

0: value1

1: value2

2: value3

How can I get the values as expected?


I tried this with a textarea and it pretty much worked.

The only thing I changed was var txt = $("#myList").text(); to var txt = $("#myList").val();.


Looks like you have a problem with the character used as line break...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜