且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

div内文本中的新行

更新时间:2023-12-03 21:44:10

换行符对html渲染没有任何作用.在您的js中更改它:

Newline characters don't do any thing to html rendering. Change this in your js:

$('.message').html($('textarea[name="mensaje"]').val());

...对此:

$('.message').html($('textarea[name="mensaje"]').val().replace(/\n/g, "<br />"));

...,它将用适当的html换行符替换您的换行符

...and it will replace your newlines with a proper html line break