- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个包含 100 个 html 页面的简单游戏,当您浏览这些页面时,随机选择的故事片段会出现在页面上。到目前为止,游戏运行得很好,但我想修改它,以便我可以将包含故事的 javascript 数组放在每个 html 页面可以调用的单个文件中,这样我就可以编辑故事一次而不更新每次添加 100 页。
最初,我的 javascript 位于“显示”div 硬编码内的每个页面上。
编辑:我按照说明编辑了代码,但它仍然没有显示。
这是我的 html 页面:
<html>
<head>
<link rel="stylesheet" type="text/css" href="layout.css">
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="story.js"></script>
</head>
<body>
<div class="header">
</div>
<div class="display_wrapper">
<div class="left_display">
</div>
<div class="display">
</div>
<div class="right_display">
</div>
</div>
<div class="left_nav">
</div>
<div class="nav">
<center>
<input type="button" id="north" value="north" onclick="window.location.href = +Math.floor(Math.random()
* 101) +'.html';" /> <br />
<input type="button" id="west" value="west" onclick="window.location.href = +Math.floor(Math.random() *
101) +'.html';" />
<input type="button" id="east" value="east" onclick="window.location.href = +Math.floor(Math.random() *
101) +'.html';" /> <br />
<input type="button" id="south" value="south" onclick="window.location.href = +Math.floor(Math.random()
* 101) +'.html';" />
</center>
</div>
<div class="right_nav">
</div>
</body>
</html>
这是我调用的 javascript:
var r_text = new Array ();
r_text[0] = "Nothings here, you should keep moving before something shows up though.";
r_text[1] = "Nothings here, you should keep moving before something shows up though.";
r_text[2] = "Nothings here, you should keep moving before something shows up though.";
r_text[3] = "You found a piece of crumbled paper on the ground. It stood out on the ground because of the
sharp contrast between the white of the paper and the red of the blood staining it. Desperate for any
clues leading out of this eerie town, you pick it up and smooth it out carefully as to not damage it
further. It reads as follows: 888 paces north, 636 paces east, 770 paces west, 946 paces west.. no end in
sight..";
r_text[4] = "You can't see anything, you don't hear anything, but a chill just shot down your spine and you
cant shake this deep feeling of uneasiness.";
r_text[5] = "A strange smell like that of a rotting corpse hits your nose. You should turn back.";
r_text[6] = "You look and look and even shout out if anyone can hear you and find nothing, but you cant
shake the feeling that you're being watched.";
r_text[7] = "You look and look and even shout out if anyone can hear you and find nothing, but you cant
shake the feeling that you're being watched.";
r_text[8] = "You walk down a street of decrep old buildings that all seem uninhabited. No one is around,
not even stray animals. For as far as you can see in every direction is nothing but more old ruined
buildings.";
r_text[9] = "You walk down a street of decrep old buildings that all seem uninhabited. No one is around,
not even stray animals. For as far as you can see in every direction is nothing but more old ruined
buildings.";
r_text[10] = "You walk down a street of decrep old buildings that all seem uninhabited. No one is around,
not even stray animals. For as far as you can see in every direction is nothing but more old ruined
buildings.";
r_text[11] = "You happen upon a building with an open doorway. The building looks stable enough to
explore so you walk up to the entrance. Near the doorway, you find an old dusty sign with writing you cant
quite read on it. After dusting the sign-off, you find out this build used to be the town's library. You
enter optimistically thinking you'll find some clues on how to leave the acursed town, or what happened
to the inhabitants. <p>Carefully you explore the internal perimeter of the library to make sure there's
nothing inside waiting for you. Upon securing that there are no other living things in the library beside
yourself, you switch to your next goal: finding information. Searching for hours and hours through
hundreds of books taken randomly from just about every shelf you skim the contents of every book looking
for some scrap of useful information. From what you can gather the town's name is Innsmouth and it used
to be a thriving fishery and gold refinery but war and inbreeding dwindled the town's population to
nearly nothing. <p>Esoteric cults moved into the desolate town with promise of economic recovery through
prayer and converted most of the surviving population, though rumors were the conversions were mostly by
force. Articles of disappearances were the only other useful bits of information that could be called
recent but the last one was dated fifteen years ago. You slump down in your chair, sigh a great sigh,
then stretch your legs and stand up to go find the nearest window. It's almost dark. You decide to spend
the night in the library. During your final inspection of the place before going to sleep for anything
lurking, you find a book that seemed wholly out of place, it looked like an ancient tome, extradanarily
thick and fantastically decorated. The very look of it was sinister. <p>For a minute you debated whether
you should look through it, toss it out of the building or find a whole other building to sleep in for
the night. Ultimately you decide you came here for useful information and this is the only book in the
a whole library that looks promising. Without picking it up, you stand near enough to read the title.. The
Necronomicon. Hesitantly, you pick the book up as if it were a venomous snake ready to strike at any
moment. Carefully you lay it on a nearby table and proceed to open the front cover.<p> You spend the
entire night pouring over the ancient time until the light of day stings your over-strained dry eyes. The
the only way to maintain your own sanity after reading the contents of The Necronomicon you resign yourself
believe this was the Bible to the esoteric cults who took over Innsmouth and it is nothing more than
religious fanatic gobbilty-gook. The world in which you and every other person on this earth and the
world portrayed in The Necronomicon just CANT be the same one. You try and try to get some sleep but
every time you close your eyes one of the frightful monsters depicted in the Necronomicon came to the
front of your mind's eye. You decide it would be best to put away the tome and not touch it again, and
focus on resting up so you may try venturing out tomorrow morning to find a way out of this increasingly
frightening town.";
r_text[12] = "You feel like you've been walking for hours without finding anything useful, any people,
animals, or ways out of the town.";
r_text[13] = "you find an abandoned general store, through the windows it looks like there may be some
rations still inside. You try for the door but its baracaded by some fallen roof beams. After surveying
the area for anything lurking and confirming that you are alone within normal earshot, you take a large
a chunk of fallen brick and break open an entrance through a large front window. The sound of the glass
breaking was the first sound you've heard in uncountable hours. Your heart pounds and you're sure SOMETHING
lurking out there heard you and must be coming after you now. You're first instinct is to hide. <p>You
hide behind a counter and scope out your surroundings fervently listening for the slightest little sound.
The sound of your own heart pounding makes it hard to hear anything else. Every time you think it's ok to
move, you realize your frightened state of mind can make five minutes feel like hours, again and again
you stop yourself from moving. Hours pass by and you notice a distinct change in the sun's position from
the shadows sprawled out on the floor. Finally, you decide its safe to venture out in search of rations
after one more survey of the inside of the store. Your efforts paid off in enough water to satisfy your
thirst and some old canned goods easily opened with tools also found in the shop you gladly chanced and
wolfed down. You decide to hold up in this store until you're fully recovered and resolved to venture out
in the town again to find a way out.";
r_text[14] = "while trying to find a suitable shelter for the soon-coming night, you walk up to a
building with an open doorway and peer inside. instantly a chill creeps down your spine. a glimpse of a
dusty sign catches your gaze and you quickly dust it off to read it. It reads: The Esoteric Order of
Dagon. This is one of the churches of the cult that took over the town and quite possibly caused the
town's mass dissertion.<p> After that terrifying realization gave way to the ability to control your
limbs again, you decide to run and find a different shelter as far away from this building as you can. ";
r_text[15] = "while walking around the town you notice most of the land appears to be flat and the
numerous old delatidated buildings made it very hard to see much more than a few hundred feet down a
single street at a time. All of a sudden you spot the first elevation you've to see since you've arrived. You
race for it to try and gain a vantage point of any kind to figure out which direction to go. The
elevation turns out to be less than 10 feet high and gives almost no vantage point as your view is still
obstructed by all of the ancient tottering buildings. You need need to climb on top of a roof to gain any
vantage. ";
r_text[16] = "during your time exploring the town you have noticed most of the roads have been unmarked
or had their street signs torn down with no remnant of the name left to be read. That fact is what made
this street before you stand out from all the other identical streets you've been walking up and down
endlessly. An intact street sign that read the Main street. What luck! It doesn't matter which direction you
follow the street, Main should always lead to other streets that will allow you to LEAVE the town! <p>You
follow the Main street for as far as your legs can take you day in and day out, only stopping during the
night to take shelter in nearby abandoned buildings, and looking for food and water. Weeks passed by and
still, not a single change in the scenery could be found, no people, no animals, everything in bitter
unyielding silence. There seems to be no foreseeable end to this street.";
r_text[17] = "the sun is high in the sky and heading toward dusk. it happens much quicker than it should
and light becomes scarce in this town with no electricity after the sun starts to come back down. This is
about the time I start looking for a shelter to stay the night in, preferably something with drinkable
water inside as the search for food was given up long ago. After trying three other houses on this street
I find one with a door I can pry open. Upon entering the house I'm overcome with the stench of mold and
mildew, which means there must be water somewhere. I decide to investigate. <p>Very silently I roam around
the house with nothing but a few sunspots to light my way. It's almost impossible to distinguish what
each room's original purpose was, there was no discernable kitchen or bathroom to be made out in such
little light without blindly groping in the dark to maybe find something that resembles a sink, toilet,
tub or exposed pipes, which was not something I was quite ignorant enough to do. Upon entering the next
room I hear something squish under my foot and feel a dampness. After walking a few more steps I discover
the entire floor is covered in less than an inch of water. I would imagine its rainwater leaked through
the same holes in the walls and roof the sunspots are coming from, however, I've been in this town for a
while now and I've not once seen it rain. <p>I kneel down and cup my hands to scoop up some water. First I
feel the texture, is it slimy, sludgy, or sooty? Next, I smell it, is it tainted or fresh rainwater? It
felt stagnant, not dirty but not necessarily fresh. It had been here a while for certain. The smell was
what threw me for a loop, it was distinctively salty, like ocean water. <p> Nonetheless, I couldn't drink
it.
I was, however, curious as to how salty ocean water got into this house. But the quickly fading sunlight
was not enough to give a thorough investigation. On my way toward what I thought was the exit, I found a
staircase leading up I had not found earlier. The light seemed the be stronger upstairs, so I thought a
few minutes of sunlight would be worth a vantage point of the town from a second-story window, and maybe
perhaps an easy-enough climb to a roof. <p>The stairs seemed sturdy enough but they creaked rather loudly
under my feet. I unconsciously held my breath as I walked up the stairs and exhaled when I could actually
see the second floor of the house, it wasn't brightly lit by any means but enough sun poured in from old
windows and holes in the roof to light the second floor well enough for it to be easily explored. The
smell of mildrew was stronger up here as well and I soon found the bottom of my shoes to be soaked.
Everything up here was wet like a firehose had been taken to it. I instinctively head toward the most
brightly lit room, hoping for an open window. Peering in the doorway I find my open window!
<p>Unfortunately, the room is flooded with several inches of water and broken household objects litterly
the floor, poking up from the water like bones from a hastily-dug grave. I decided to check the other
rooms first. The second room I try has a closed door and it won't budge, it seems to be baracaded from the
other side. The next room is open but there's a large hole in the middle of the floor and it doesn't seem
to be stable enough to walk across to get to the nearest window. The first room is the best option.
-------------------------------------- ";
r_text[18] = "Nestled down in my shelter for the night, having made sure all was quiet and vacant before
attempting to fall asleep. Abruptly, in the dead of the night, I'm awakened by the croaking of frogs
outside. Up until this very moment I hadn't heard or seen so much as a living insect, let alone a frog.
This disturbed me greatly.";
r_text[19] = "saw a fishfrog creature";
r_text[20] = "saw a cultist group";
r_text[21] = "saw cthulhu";
r_text[22] = "hear noises";
r_text[23] = "chased by a cultist";
r_text[24] = "find cultist materials";
r_text[25] = "spot cultists or fishfrogs on devils reef";
r_text[26] = "chased by fishfrogs";
r_text[27] = "found an underground tunnel";
r_text[28] = "cthulhu dreams";
r_text[29] = "I hear strange spectral piping";
r_text[30] = "when i saw the people, or what i thought were people, i instantly shouted out to them to
get their attention. i wish i hadnt done that.";
r_text[31] = "a night of despair";
r_text[32] = "i thought it was a dream but it wasnt, how did I get here?";
r_text[33] = "going inside a church to investigate";
r_text[34] = "event 34";
r_text[35] = "event 35";
r_text[36] = "event 36";
r_text[37] = "event 37";
r_text[38] = "event 38";
r_text[39] = "event 39";
r_text[40] = "event 40";
r_text[41] = "event 41";
r_text[42] = "event 42";
r_text[43] = "event 43";
r_text[44] = "event 44";
r_text[45] = "event 45";
r_text[46] = "event 46";
r_text[47] = "event 47";
r_text[48] = "event 48";
r_text[49] = "event 49";
r_text[50] = "event 50";
var i = Math.floor(51*Math.random())
document.getElementsByClassName("display")[0].append( r_text[i] );
最佳答案
链接标签不用于 JavaScript。您想要这个标签:
<script type="text/javascript" src="whateverYourFileIsCalled.js"></script>
你的JS文件中不应该有任何脚本标签;它应该只是 JavaScript,没有任何 HTML。
关于javascript - 如何调用保存在单独文件中的 JavaScript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31572554/
今天我在一个 Java 应用程序中看到了几种不同的加载文件的方法。 文件:/ 文件:// 文件:/// 这三个 URL 开头有什么区别?使用它们的首选方式是什么? 非常感谢 斯特凡 最佳答案 file
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个 javascript 文件,并且在该方法中有一个“测试”方法,我喜欢调用 C# 函数。 c# 函数与 javascript 文件不在同一文件中。 它位于 .cs 文件中。那么我该如何管理 j
需要检查我使用的文件/目录的权限 //filePath = path of file/directory access denied by user ( in windows ) File fil
我在一个目录中有很多 java 文件,我想在我的 Intellij 项目中使用它。但是我不想每次开始一个新项目时都将 java 文件复制到我的项目中。 我知道我可以在 Visual Studio 和
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有 3 个组件的 Twig 文件: 文件 1: {# content-here #} 文件 2: {{ title-here }} {# content-here #}
我得到了 mod_ldap.c 和 mod_authnz_ldap.c 文件。我需要使用 Linux 命令的 mod_ldap.so 和 mod_authnz_ldap.so 文件。 最佳答案 从 c
我想使用PIE在我的项目中使用 IE7。 但是我不明白的是,我只能在网络服务器上使用 .htc 文件吗? 我可以在没有网络服务器的情况下通过浏览器加载的本地页面中使用它吗? 我在 PIE 的文档中看到
我在 CI 管道中考虑这一点,我应该首先构建和测试我的应用程序,结果应该是一个 docker 镜像。 我想知道使用构建环境在构建服务器上构建然后运行测试是否更常见。也许为此使用构建脚本。最后只需将 j
using namespace std; struct WebSites { string siteName; int rank; string getSiteName() {
我是 Linux 新手,目前正在尝试使用 ginkgo USB-CAN 接口(interface) 的 API 编程功能。为了使用 C++ 对 API 进行编程,他们提供了库文件,其中包含三个带有 .
我刚学C语言,在实现一个程序时遇到了问题将 test.txt 文件作为程序的输入。 test.txt 文件的内容是: 1 30 30 40 50 60 2 40 30 50 60 60 3 30 20
如何连接两个tcpdump文件,使一个流量在文件中出现一个接一个?具体来说,我想“乘以”一个 tcpdump 文件,这样所有的 session 将一个接一个地按顺序重复几次。 最佳答案 mergeca
我有一个名为 input.MP4 的文件,它已损坏。它来自闭路电视摄像机。我什么都试过了,ffmpeg , VLC 转换,没有运气。但是,我使用了 mediainfo和 exiftool并提取以下信息
我想做什么? 我想提取 ISO 文件并编辑其中的文件,然后将其重新打包回 ISO 文件。 (正如你已经读过的) 我为什么要这样做? 我想开始修改 PSP ISO,为此我必须使用游戏资源、 Assets
给定一个 gzip 文件 Z,如果我将其解压缩为 Z',有什么办法可以重新压缩它以恢复完全相同的 gzip 文件 Z?在粗略阅读了 DEFLATE 格式后,我猜不会,因为任何给定的文件都可能在 DEF
我必须从数据库向我的邮件 ID 发送一封带有附件的邮件。 EXEC msdb.dbo.sp_send_dbmail @profile_name = 'Adventure Works Admin
我有一个大的 M4B 文件和一个 CUE 文件。我想将其拆分为多个 M4B 文件,或将其拆分为多个 MP3 文件(以前首选)。 我想在命令行中执行此操作(OS X,但如果需要可以使用 Linux),而
快速提问。我有一个没有实现文件的类的项目。 然后在 AppDelegate 我有: #import "AppDelegate.h" #import "SomeClass.h" @interface A
我是一名优秀的程序员,十分优秀!