cuốn sách gpt4 ai đã làm

javascript - 来自javascript的换行符/样式文本?

In lại Tác giả: Walker 123 更新时间:2023-11-28 12:54:50 25 4
mua khóa gpt4 Nike

所以首先,这可能有点长。我正在尝试使用 javascript 制作 RPG 文本游戏。

在我的 HTML 中,我只有 html、head、css、body、div 和 script 标签。



<đầu>






Xem sitemap của VNExpress

所以这纯粹是我游戏信息的容器。

然后我有我的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;
phá vỡ;

case "ARCHER":
ATTACK = 6;
STRENGTH = 5;
DEFENSE = 11;
RANGED = 20;
MAGIC = 3;
AGILITY = 15;
HEALTH = 175;
phá vỡ;
}

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 部分时,它只是把它作为一大段文本,即使它们来自不同的提示。有人可以帮我告诉我如何设计它吗?

câu trả lời hay nhất

document.write("

A sample heading

\

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("

A sample heading

\

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.

");

Bạn có thể sử dụng backslash在 javascript 中将字符串拆分为不同的行。

您可以使用不同的文本标记,例如

对于段落

用于 heading1 等来设置文本样式,而文本又是 HTML 的一部分.更多风格,您可以查看 css .

如果你想在 javascript 中换行使用 \Nhoặc \t对于选项卡。这仅用于输出格式。

如果你想在 HTML 中换行结果,使用

Also the document.write method is deprecated and not recommended, if you are serious about your programming. You have to resort to better DOM manipulation methods like document.createElement appendChild etc to create a document dynamically.

Dynamically create a HTML form with Javascript

关于javascript - 来自javascript的换行符/样式文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16610299/

25 4 0
Đề xuất bài viết: jquery - 选择在 IE8 中无法正常工作
Đề xuất bài viết: html - 需要 2 个 100% 宽度的文本框,分为 2 个(50% x 50%)以及一个提交按钮
Đề xuất bài viết: php - 通过网络 (PHP) 打印 800 毫米(收据)表
Đề xuất bài viết: css - 更改导航栏高度
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Các bài viết phổ biến trên toàn bộ trang web
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com