javascript中的换行/样式文本
line breaks/ styling text from javascript?
首先,这可能有点长。我正在尝试使用javascript制作一款RPG文本游戏。
在我的HTML,所有我有HTML,头部,css,主体,一个div和脚本标签。
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="story_css.css">
</head>
<body>
<div class="container">
<script src="story_js.js"></script>
</div>
</body>
</html>
所以这将纯粹是我的游戏信息的容器。
然后我有我的javascript:var ATTACK = 0;
var STRENGTH = 0;
var DEFENSE = 0;
var RANGED = 0;
var MAGIC = 0;
var AGILITY= 0;
var HEALTH = 0;
var CLASS = prompt("Choose a class (class only effects starting stats, but all classes can learn the same abilities at the same rate):Warrior, Mage, Theif, Archer.").toUpperCase();
switch (CLASS){
case "WARRIOR":
ATTACK = 16;
STRENGTH = 18;
DEFENSE = 17;
RANGED = 2;
MAGIC = 2;
AGILITY = 5;
HEALTH = 200;
break;
case "ARCHER":
ATTACK = 6;
STRENGTH = 5;
DEFENSE = 11;
RANGED = 20;
MAGIC = 3;
AGILITY = 15;
HEALTH = 175;
break;
}
document.write("These are the levels for each of your characters skills. You may write these down and keep track of them, but the game will automatically record your progress for you. However, you will not be able to see your levels until you type a command that asks for them, or if you require a certain level to complete a task.")
var NAME = prompt("Enter your name:");
confirm("You are about to embark on an epic quest... so, " + NAME + " are you ready to begin?");
document.write("It is the year 3355, according to the Delil calendar, and you awake from your night's sleep. Today is a special day. It is your 18th birthday! In your small village of Shadowhollow, you are one of the 23 people who live there. But as of today, you are one of the villages men.");
我的问题是,当javascript做文档。写的部分,它只是把它作为一个巨大的文本,即使他们来自不同的提示。有人能帮我一下,告诉我怎么做吗?
document.write("<h2>A sample heading</h2>'
<p>These are the levels for each of your characters skills.'
You may write these down and keep track of them, but the game will automatically record your progress for you.'
However, you will not be able to see your levels until you type a command that asks for them, '
or if you require a certain level to complete a task.</p>");
var NAME = prompt("Enter your name:");
confirm("You are about to embark on an epic quest... so, " + NAME + " are you ready to begin?");
document.write("<h2>A sample heading</h2>'
<p>It is the year 3355, according to the Delil calendar, and you awake from your night's sleep. '
Today is a special day. It is your 18th birthday! In your small village of Shadowhollow, you are one of the 23 people who live there. '
But as of today, you are one of the villages men.</p>");
您可以使用backslash
在javascript中将字符串拆分为不同的行。
您可以使用不同的文本标记标签,如<p>
为段落<h1>
为标题1等样式文本,这反过来是HTML
的一部分。更多的样式,你可以看看css
。
如果你想在javascript中换行,使用'n
或't
的制表符。这只是用于输出格式化。
如果你想在HTML
结果中换行,使用<br>
也不推荐使用
document.write
方法,如果你对编程很认真。你必须求助于更好的DOM操作方法,如document.createElement
appendChild
等来动态创建文档。
用Javascript动态创建HTML表单
为什么不用HTML构建文本?:
document.write('<p>...</p>');
...
document.write('<p>...</p>');
相关文章:
- 具有所有样式的文本正在复制到可编辑文本区域
- 将Div内容复制到文本区域或具有相同字体族样式的文本
- 为未标记的文本添加CSS样式
- 尝试在随机文本和图像脚本中添加样式/更改字体
- HTML + JS:设置文本区域内容样式的最佳方式
- 如何更改列表中一个元素中的文本样式
- 如何检查与显示:无样式相关的文本内容
- 如何使用 JavaScript 将样式应用于 CKEditor 中的选定文本
- 输入占位符文本转换CSS样式
- 如何优化动态生成多列文本样式
- GWT:如何从当前光标位置或所选文本中获取css样式的属性
- 用于丢失文本样式的脚注的Indesign脚本
- Jquery 在 ASP 文本框上添加样式不起作用
- 如何更改chardin.js中的文本颜色和样式
- 为HTML文本区域设置标题属性的样式
- 遵循 jquery Mobile 的文本框样式
- 将样式添加到文本区域的特定行
- 多语言丢失文本样式
- 将文本区域样式化,使其看起来像单独的输入框
- javascript中的换行/样式文本