我有一个按钮‘编辑描述’,当我点击它的文字消失并出现
if (id == 'commedit') jQuery(this).html('<textarea>'+jQuery(this).text()+'</textarea>');
else if (id == 'commsave') {
jQuery(this).text(jQuery(this).find('textarea').val());
}在MySql中,我有这个text - "tetee<br>afafaf<br>afafaf<br>afsafsasfasf"视图,它没有换行符,但是当我在文本区域中点击‘编辑’时,它会出现而没有换行符,当我点击保存时,它也会出现在我的描述字段中的一个没有换行的长行中。所以我需要你的帮助
发布于 2012-08-23 02:25:41
<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);
}https://stackoverflow.com/questions/12079160
复制相似问题