一次单击一下即可在句子中显示大字符串
Displaying a large string in sentences one click at a time
#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元素,当单击时,一串文本以一个巨大的块写入页面。
我的问题是,我怎样才能让它一次只加载一个句子,然后单击时,加载下一个句子,然后加载下一个句子,直到字符串中没有其他内容?
虽然我不太确定,但您要完成的是什么,我使用您的代码作为基础为您制作了一个演示,(希望(可以满足您的需求:
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
相关文章:
- jQuery:如何添加<br/>在不同的字符串中换行以分隔2中的句子
- 一次单击一下即可在句子中显示大字符串
- 设置小写字符串的格式,使每个句子的开头都大写
- 将句子大小写应用于可能包含HTML的字符串
- 在javascript中将字符串拆分为句子
- 在一个句子中搜索多个字符串
- 计算长字符串中每个句子的单词,jQuery
- Jquery 解析不属于字符串的句子/行中的整数
- 将句子字符串拆分为单词数组,然后将单词数组拆分为单词数组中的字符数组
- 计算字符串中的句子数,同时在 JavaScript 中考虑小数
- 在javascript中将字符串转换为句子大小写
- 使用 JavaScript 计算字符串中的句子
- 将字符串拆分为句子 - 忽略用于拆分的缩写
- 如何将Javascript字符串拆分为少于140个字符的句子
- 如何忽略字符串索引中的空格,并在句子中的每个单词上以大写字母开头
- 将句子字符串分成子字符串=<最长单个单词的长度
- 如何在计算句子中字符串的出现次数时考虑标点和大写
- 我如何使用简单的子字符串函数在javascript标题大小写句子
- .split()用于句子字符串的元素,高级分隔符
- 如何用javascript从字符串中提取句子