【发布时间】:2021-09-16 16:55:52
【问题描述】:
我在使用反引号时遇到了一些问题,我想知道是否有人可以帮助我。我有下面的代码,它允许我输出多个响应。问题是,当我在 target="_blank">here` 后面加上逗号时,它不允许我添加更多短语。我曾尝试在反引号之前使用退格键来突破它,但没有运气。这是我的代码,我使用的是 Javascript 和 HTML。
<script>
function talk(){
var know ={
"How does this work":"I can help you find what you're looking for.",
"how does this work":"I can help you find what you're looking for.",
"contact":`You can contact us by clicking <a href='https://addressname.com' target="_blank">here</a>`
};
var user = document.getElementById('userBox').value;
document.getElementById('chatLog').innerHTML = user + "<br>";
if(user in know){
document.getElementById('chatLog').innerHTML = know[user] + "<br>";
}else{
document.getElementById('chatLog').innerHTML = "I do not understand.";
}
}
</script>
为了澄清,我需要这样的东西:(但显然逗号不起作用)
"How does this work":"I can help you find what you're looking for.",
"how does this work":"I can help you find what you're looking for.",
"contact":`You can contact us by clicking <a href='https://addressname.com'target="_blank">here</a>`,
"help":`You can find help by clicking <a href='https://addressname.com'target="_blank">here</a>`
【问题讨论】:
-
这对我有用:jsfiddle.net/jfhxey65。你遇到了什么错误?
-
@BankBuilder 太奇怪了,它现在对我来说很完美。谢谢!也许我最初在某个地方使用了撇号而不是反引号。
标签: javascript html template-literals backticks