var text = $('#theId').val(); var tempText = text.replace(new RegExp('\n',"gm"),'<br/>'); // 后面的gm是全局替换