2014-02-23 70 views
0

我做錯了什麼?帶變量的jQuery textarea值字符串

我需要這樣的代碼中設置textarea的值作爲字符串變量我一條線,但現在:

$('#a1').val(currentVal + '[quote author="' + comment_author + '" date="' + comment_date + '"]' + comment_text + '[/quote]'); 

它產生我與新生產線的價值,如:

   [quote author=" 
        Гость 
       " date=" 
        23.02.14 11:26 
       "] 

        sometextgoeshere 
       [quote] 

如何將它設置在一行中?沒有斷線?

UPD:只是這一部分:

'[quote author="' + comment_author + '" date="' + comment_date + '"]' + comment_text + '[/quote]' 

必須是沒有換行符。 只是斷行的文本(註釋)必須與線斷裂,僅分離部分的像「[報價作者=「」 + COMMENT_AUTHOR必須在同一行

回答

0
var newVal = currentVal + '[quote author="' + comment_author.trim() + '" date="' + comment_date.trim() + '"]' + comment_text.trim() + '[/quote]' 
//var newVal = newVal.replace(/\s|\n|\r|\t+/g, ' '); 
$('#a1').val(newVal); 
+0

只是斷行的文本(註釋)必須與線斷裂,僅分離部分的像「[報價作者=「」 + COMMENT_AUTHOR必須在同一行 –

+0

也許我知道在世界衛生大會t是troube:我有這樣的HTML: '<跨度類=「缺口」> Гость ' ,我需要獲取從這個跨度僅文本,而無需新的線,前和在這種情況下的文字等 –

+0

後空格你可以使用修剪功能,如comment_author.trim()..編輯答案 –

0

您可以設置wrap屬性off

DEMO jsFiddle

<textarea id="a1" wrap="off"></textarea>