我在页面上有一个简单的 JS 测验,它生成问题结果的答案并将其放入 html 中。在几个答案中,我喜欢说“了解更多信息,请点击此处”。如何将链接添加到要放入 html 的 JS 字符串中?
我对 JS 很陌生,所以不太确定如何解决这个问题......
这是被调用的 JS:
{ // Question
"q": "<h4>Is it recommended to use one vial of BOTOX<sup>®</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/