for (i = 0; i < json.people[NPC_id].dialogs.start.options.length; i++) {
concat += "\n "+ optionNumbers + ") " + json.people[NPC_id].dialogs.start.options[i].text;
optionNumbers++;
}
//append JSON dialog to label...
options = concat;
我在这里更新HUD:
function updateHUD() {
console.log(options);
$('#options').html(options);
}
然后更新HTML:
<div id="bottomDisplay">
<ul>
<li><b>Options:</b> <div id="options"></div> </li>
</ul>
</div>
Console.log提供格式化的concat
字符串...
1) What is wrong with it?
2) What is a 狗?
3) Sorry, I don't have time :/
但是html出现在未格式化的div id中:
1) What is wrong with it? 2) What is a 狗? 3) Sorry, I don't have time :/
为什么?
答案 0 :(得分:4)
HTML不处理多个空格或新行。
你可以:
<pre>
元素中(最简单的就是拥有<pre id=options></pre>
)\n
替换为<BR>
:options = options.replace(/\n/g,'<br>')