在 Javascript 中使用引号和 innerHTML

2023-11-27

我编写了一些代码来让玩家了解故事的进展。当玩家单击按钮时,他们会看到一些新文本和更多选项。到目前为止一切顺利,但是当我传递带有附加参数的函数调用时,我需要单引号和双引号。但是,如果我同时使用两者,则会破坏innerHTML。代码如下(如果需要也可以发布HTML):

function buttonClicked(buttonid)  {
     switch(buttonid) {
    case "YesStart":
        document.getElementById("storybox").innerHTML = "Initially she fails to notice you and stares into the distance with dazed look of someone who has considered the exact point at which the universe might have ended, present within a kind of altered dimensionality that places her materially at a similar point of existence to you, while leaving her utterly absent from it in some other, more absolute sense. Two nuns scurry past her, heading towards a small, fluffy dog, who they pet while making cooing sounds; a stern man in an ill-fitting police officer's uniform eyes them suspiciously. This spectacle seems to rouse her from her trance, and she looks quizzically at them, tilting her head to one side, before spotting you out of the corner her eye and waving you over.</p><p>When you arrive at the hotel it is empty but for two bleary eyed reception staff who stare as you walk past. Deer-Wolf tells you this is the place where the murderer lives. He rents a different room each week, always under different assumed names. He tells people this is because he is married, and likes to take women back unnoticed. The staff have never seen one leave, but the room is always impeccably kept, so the uneasy feeling the hotel staff have about him has never yet been officially corroborated.</p>";
        break;
    case "NoStart":
        document.getElementById("storybox").innerHTML = "<p>You try to fall asleep in your bed but you cannot. Your heart is beating so fast you feel like it will fail. All night you are plagued by images of your still conscious body being cut open at autopsy. You wake up often. During the days you are afraid to be left alone. The only solace you have is a lady who calls herself Deer-Wolf, who texts you often and calls you on occasion. You find her voice comforting but you are still afraid, and feel that you will never be fully safe until you solve the case. You ask your friends for help, even offer to pay them to investigate but they either ignore you, decline, or tell you to go away. You are not sure if they believe you and are too scared, or if they think you are crazy. Either way, they won't help.</p><p>Do you choose to investigate?</p>
        <button type='button' class='btn btn-success' id='yesbtn' onclick='buttonClicked('YesStart')'>Yes</button><button type='button' class='btn btn-danger' id='nobtn' onclick='buttonClicked('NoStart')'>No</button>";
        break;
    default:
       console.log("Do you write your button function call correctly? Bad function call. Bad.");
    };

};

有人能提出解决方案吗?


你必须用 \ 来逃避它们。

"This is a string with \"quotation\" marks."

如何在字符串中包含引号

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Javascript 中使用引号和 innerHTML 的相关文章

随机推荐

  • 将 3x1 或 1x3 cv::Mat 转换为 cv::Point3d?

    我正在处理一些代码 其中执行大量 3x3 矩阵乘法 还使用旋转矩阵对 3d 点进行一些转换等 我决定使用 OpenCV 核心功能进行数学运算 使用最近添加到的构造函数的可能性cv Mat类来转换cv Point3d直接到 3x1cv Mat
  • Mongodb 模式,具有唯一值的字符串数组

    我正在为 mongo 文档创建模式 除了防止非对象数组中的重复之外 我可以做所有事情 我知道 addToSet 但我指的是 Mongo Schema 我不想使用 addToSet 检查更新 而是希望这是我的架构验证的一部分 下面的例子 le
  • 使用 MyBatis 将集合持久保存在对象中

    我有 POJO 课程 class Ticket private int id private double cost private Date time private List
  • 以编程方式更改 PowerShell 控制台字体

    我开发了一个使用 PowerShell 充当基于控制台的应用程序 例如 ncurses 的脚本 字体露西达控制台在脚本的快捷方式中配置 我想为用户提供更改字体大小的能力 以下模块就是这样做的 但是字体始终重置为 光栅字体 https 4sy
  • Ajax.ActionLink 与 mvc 核心的替代方案

    在MVC5中有 Ajax ActionLink这对于仅更新部分视图而不是重新加载整个视图很有用 显然在 MVC6 中不再支持 我尝试过使用 Html ActionLink如下所示 但它不会更新表单 它仅返回部分视图 View Html Ac
  • 模板类中对友元函数的未定义引用

    以下代码位于Heap h文件中 template
  • 攻击者可以有害地使用检查元素吗?

    我知道这是一个广泛的问题 但我认为我在这里遗漏了一些东西 攻击者是否可以通过简单地使用检查元素并编辑 javascript 和 html 来对站点造成损坏 例如 对于某人来说 更改输入的最大长度并上传太多数据可能会导致服务器崩溃 这似乎太容
  • C# 中的数组大小(长度)

    如何在 C 中确定数组的大小 长度 项目数 如果是一维数组a a Length 将给出的元素数量a If b是一个矩形多维数组 例如 int b new int 3 5 b Rank 将给出维数 2 和 b GetLength dimens
  • 多处理函数上的超时装饰器

    我有这个装饰器直接取自我在网上找到的一个例子 class TimedOutExc Exception pass def timeout timeout def decorate f def handler signum frame rais
  • 如何从 Azure DevOps 部署到 AWS Kubernetes

    我使用 Azure DevOps 来处理 PBI 存储库 PRS 和构建 但我的所有基础设施 包括 Kubernetes 均由 AWS 管理 没有文档 也没有关于如何使用 Azure DevOps 任务部署到 AWS EKS 的 正确且简单
  • 翻译动画的工作原理:Android

    我正在尝试移动一个RelativeLayout using TranslateAnimation 我为执行相同操作而编写的代码是 translateAnimation new TranslateAnimation 0 0 heightOfR
  • Spring HandlerInterceptors是如何实例化的?

    每个请求是否都有一个新的 Spring HandlerInterceptors 实例 我在 Spring 中有一个拦截器 它有一个类字段 public class MyInterceptor extends HandlerIntercept
  • 在 Cocoa KVO 中,为什么 NSMutableArray 代理上的更改不会通知观察者?

    我正在实施一个DocumentsManageriOS 中的类 我想创建一个名为的多对多属性documents符合 KVO 要求 它似乎大部分工作 并且我的 KVO 访问器和修改器方法被调用 然而 令我困扰的是 直接在NSMutableArr
  • 使用facet时ggplot2在面板边框之外

    我希望在多面图的外部有一个边框 但没有分隔图内面板的线 问题是 panel border 在构面中的每个面板周围绘制一个边框 而没有选择只在整个图周围有一个边框 或者 您可以将内部分隔线设置为 白色 但保持外部边框为 黑色 这是我的代码 m
  • Xcode 项目范围编译器标志

    使用 Xcode 4 2 和 LLVM 编译器 在针对 ARMv6 进行编译时 生成的应用程序中存在一些非常奇怪的错误 例如 CGSize 的 width 属性返回 height 为了解决这个问题 我发现我必须设置编译器标志 mno thu
  • 如何使用 requests 库发送 xml 正文?

    def request encoded xml urllib urlencode XML read xml encoded xml read xml headers Authorization AUTH TOKEN developerTok
  • 为什么应用太多参数会抛出“超出最大调用堆栈大小”?

    在 Chrome 和 Node 中 以下代码会引发错误 function noop var a new Array 1e6 Array 1000000 noop apply null a Uncaught RangeError Maximu
  • addActionListener 有什么作用?

    我有以下代码 JButton button new JButton Clear button addActionListener this 据我了解 我创建了一个按钮 上面写着 清除 然后我必须将一个动作与这个按钮关联起来 如果按下按钮会发
  • Python gc.get_count() 返回的 count0、count1 和 count2 值是什么

    python gc 包的文档对 gc get count 做了这样的描述 gc get count Return the current collection counts as a tuple of count0 count1 count
  • 在 Javascript 中使用引号和 innerHTML

    我编写了一些代码来让玩家了解故事的进展 当玩家单击按钮时 他们会看到一些新文本和更多选项 到目前为止一切顺利 但是当我传递带有附加参数的函数调用时 我需要单引号和双引号 但是 如果我同时使用两者 则会破坏innerHTML 代码如下 如果需