Javascript 在数组中添加新行
我有以下代码:Javascript 在数组中添加新行,javascript,jquery,Javascript,Jquery,我有以下代码: $('.getcode').click(function () { $('textarea').val(""); var str = []; $('#group-wrap span').each(function () { str.push($(this).attr('title') + $(this).text()); }); $('textarea').val(str.jo
$('.getcode').click(function () {
$('textarea').val("");
var str = [];
$('#group-wrap span').each(function () {
str.push($(this).attr('title') + $(this).text());
});
$('textarea').val(str.join(''));
});
它获取每个跨度的内容和跨度的每个标题属性的值,并将其附加到textarea字段
<span class="grouptitle" title="&f">Group</span> (Multiple spans like this)
我有一个按钮,当单击时,会附加一组新的元素
var = groupClone = $('.wrapper'); //wrapper for the span's
$('.add').click(function(){
groupClone.first().clone().appendTo('#group-wrap');
});
它有点工作,除了现在的输出是这样,如果我添加另一个:
&f(&fGroup&f) &fUsername&f:&f Hello There!&f(&fGroup&f) &fUsername&f:&f Hello There!
如何添加新行(\n我假设?)以使输出是文本区域中的这一行
&f(&fGroup&f) &fUsername&f:&f Hello There!
&f(&fGroup&f) &fUsername&f:&f Hello There!
非常简单,但这应该是可行的
$('.add').click(function(){
$('#group-wrap').html($('#group-wrap').html() + "\n"); // add a newline to the group-wrap element
groupClone.first().clone().appendTo('#group-wrap'); // append the copied data in
});
$('.add').click(function(){
$('#group-wrap').html($('#group-wrap').html() + "\n"); // add a newline to the group-wrap element
groupClone.first().clone().appendTo('#group-wrap'); // append the copied data in
});