如何在查询文本中更改新行?

时间:2015-05-15 19:13:15

标签: javascript jquery

 $('#collapseExmaplewell').html("Results number is" + t.finished_hits + "<br />Task results are as following:" + t.detailed_results);

如果t.detailed_results是JSON字符串,如何将\r更改为正确的换行符?

2 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

var str = t.detailed_results.replace(/\r/g, "<br>");
$('#collapseExmaplewell').html("Results number is" + t.finished_hits + "<br />Task results are as following:" + str);

您应该阅读有关正则表达式here的更多信息。

答案 1 :(得分:0)

$('#collapseExmaplewell').html("Results number is" + t.finished_hits + "<br />Task results are as following:" + t.detailed_results.replace(/\r/g, '\n<br>'));