nl2br() equivalent in javascript [duplicate]
问题 Possible Duplicate: jQuery convert line breaks to br (nl2br equivalent) Currently I add <BR> for each evt.which == 13 . Is there a nl2br() for JavaScript, so I can do away with this evt.which == 13 ? How different is this from php.js $('#TextArea').keypress(function(evt) { if (evt.which == 13) { var range = $('#TextArea').getSelection(); var image_selection = range.text; $('#TextArea').replaceSelection('<BR>'); $('#TextArea1').html($('#TextArea').val()); } }); 回答1: Take a look at nl2br on php