在textarea中的每个逗号后输入换行符

问题描述 投票:-1回答:1

我希望在我的textarea中每个创建的逗号后输入新行。

<textarea id="update_destination" placeholder="Podpiete adresy" class="form-control"></textarea>

而且我如何填写我的文本区域

$("#update_destination").val(alias.destination);

别名是一个对象。

现在在我的textarea我得到了像xxx,yyy,zzz我想要的东西:

XXX

YYY

ZZZ

javascript jquery
1个回答
0
投票

试试这段代码:

$('#update_destination').val(alias.destination.split(",").join("\n"));

您可以轻松查看this fiddle

有关this Stackoverflow Link的更多详细信息,请参阅replace all occurrences of all string

© www.soinside.com 2019 - 2024. All rights reserved.