javascript - 如何将链接添加到 JS 驱动的测验答案中?

标签 javascript html hyperlink

我在页面上有一个简单的 JS 测验,它生成问题结果的答案并将其放入 html 中。在几个答案中,我喜欢说“了解更多信息,请点击此处”。如何将链接添加到要放入 html 的 JS 字符串中?

我对 JS 很陌生,所以不太确定如何解决这个问题......

这是被调用的 JS:

{ // Question
  "q": "<h4>Is it recommended to use one vial of BOTOX<sup>&reg;</sup> on more than one patient?</h4>",
  "a": [
  {"option": "TRUE",      "correct": false},
  {"option": "FALSE",     "correct": true}
  ],
  "correct": "<p><span>CORRECT!</span> As the diluents in BOTOX<sup>®</sup> do not contain a preservative it is not recommended to use on more than one patient.2 If you would like to refer to this information again, it can be found via the link below.</p>",
  "incorrect": "<p><span>INCORRECT.</span> As the diluents in BOTOX<sup>®</sup> do not contain a preservative it is not recommended to use on more than one patient.<sup>2</sup> If you would like to refer to this information again, it can be found via the link below.</p><p>***here is where I would like the link to be***</p>" 
},

最佳答案

您可以使用 link() 方法在 JavaScript 中包含链接:

var str = "This is the text that will show up";
var textToPrint = str.link("http://samplewebsite.com");

您现在可以打印出textToPrint,它会像这样打印出来:This is the text that will show up

关于javascript - 如何将链接添加到 JS 驱动的测验答案中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41052326/

相关文章:

javascript - 输入类型 ="file"上的点击事件触发不起作用

javascript - AngularJS 从 PHP 文件获取数据

c++ - 如何使 QGraphicsTextItem 可点击?

PHPMailer:超链接出现在 outlook 中的括号中

javascript - nodejs C++ 插件中的访问器

javascript - AngularJS:从表单中获取值(value)

javascript - 如何(不)嵌套 `then` 生成 Promise 方法?

html - CSS自定义复选框不隐藏:after and :before elements

javascript - 在 if 语句中仅回显文本一次

asp.net - HttpUtility.UrlEncode() 和 Server.UrlEncode() 未对 asp.net 4.0 中的 URL 进行编码