gpt4 book ai didi

javascript - 一次单击一次显示句子中的大字符串

转载 作者:行者123 更新时间:2023-12-03 07:11:30 24 4
gpt4 key购买 nike

#branchID pool
branch0 = "This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text."
branch1 = "This is a second wall of text."
branch2 = "This is a third wall of text."

#classes section
#pulls text from pools above.
branch = (name, branchid)->
stringID = String(branchid)
document.write("<h1 id=\'#{stringID}\'>#{name}</h1>")
document.getElementById(stringID).onclick = ->
document.write(branchid)

#This is where the game goes. It will be built with conditionals
window.onload = ->
branch('Start', branch0)

我正在使用 CoffeeScript 创建一个基于浏览器的“选择你自己的冒险”游戏。上面是我到目前为止的代码。它创建一个 HTML 元素,单击时,一串文本会以一个巨大的 block 的形式写入页面。

我的问题是,我怎样才能做到一次只加载一个句子,然后单击时加载下一个句子,然后加载下一个,直到字符串中没有其他内容为止?

最佳答案

虽然我不太确定,您想要完成的任务是什么,我使用您的代码作为基础为您制作了一个演示,(希望)可以实现您想要的功能:

https://jsfiddle.net/Exinferis/qhr7wjmu/

#branchID pool
firstBranch = [
"This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text. This is a wall of text."
"This is a second wall of text."
"This is a third wall of text."
]

currentStep = 0

#classes section
#pulls text from pools above.
branch = (event)->
if firstBranch[currentStep]?
document.getElementById( "text" ).innerHTML = firstBranch[currentStep]
currentStep++

#This is where the game goes. It will be built with conditionals
window.onload = ->
document.getElementById( "nextbtn" ).onclick = branch

关于javascript - 一次单击一次显示句子中的大字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36602127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com