HTML:
<p id="value">
Challange Accepted.\nTested Ok
</p>
JS:
var result = jQuery('#value').text();
var response = String(result);
alert(response);
我的小提琴:https://jsfiddle.net/prg5h1zy/15/#&togetherjs=Rx9GCd4GAs
答案 0 :(得分:2)
您需要将\n
文字替换为行为类似新行的\n
:
var result = jQuery('#value').text();
var response = result.replace(/\\n/g,"\n");
alert(response);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="value">
Challange Accepted.\nTested Ok
</p>
&#13;