![](/img/trans.png)
[英]jquery post encodeURIComponent and textarea line break issue
[英]textarea line break jquery
當我單擊它時,我有一個按鈕“編輯描述”,文本消失並顯示
if (id == 'commedit') jQuery(this).html('<textarea>'+jQuery(this).text()+'</textarea>');
else if (id == 'commsave') {
jQuery(this).text(jQuery(this).find('textarea').val());
}
在MySql中,我有此文本- "tetee<br>afafaf<br>afafaf<br>afsafsasfasf"
,因為它沒有換行符,但是當我在文本區域中單擊“ edit”時,Jquery文本附帶的文本沒有行,當我單擊“保存”,它也會在我的描述字段中顯示為一長行而沒有換行符。 所以我需要你的幫助
<br>
是html中斷。 您想在文本區域中輸入\\n
。
jQuery(this).html().replace(/<br>/gi,"\n")
保存時,您想將其更改回中斷並使用html()而不是text();。
var elem = jQuery(this);
if (id === 'commedit') {
var text = jQuery(this).html().replace(/<br>/gi,"\n");
elem.html('<textarea>'+ text +'</textarea>');
} else if (id === 'commsave') {
var html = elem.find('textarea').val().replace(/\n/g,"<br>");
elem.html(html);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.