在 Javascript 中多次使用反引号
Multiple use of backticks within Javascript
我在使用反引号时遇到了一些问题,我想知道是否有人可以帮助我。我有下面的代码,它允许我输出多个响应。问题是,当我在 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>`
如你所知"
& '
的使用应该是一一对应的
属性值周围的双引号在 HTML 中最常见,但也可以使用单引号。
在某些情况下,当属性值本身包含双引号时,需要使用单引号:
<p title='John "ShotGun" Nelson'>
反之亦然:
<p title="John 'ShotGun' Nelson">
反斜杠(\
)转义字符将特殊字符转换为字符串字符。
如果中间有额外的符号,您可以在它们之前使用 \
反斜杠,这样它们就不会干扰代码并被视为这样的符号:
<p title="John \'ShotGun\' Nelson you\'re a good\bad person">
它将显示如下:
John 'ShotGun' Nelson 你是 good\bad 人
我在使用反引号时遇到了一些问题,我想知道是否有人可以帮助我。我有下面的代码,它允许我输出多个响应。问题是,当我在 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>`
如你所知"
& '
的使用应该是一一对应的
属性值周围的双引号在 HTML 中最常见,但也可以使用单引号。
在某些情况下,当属性值本身包含双引号时,需要使用单引号:
<p title='John "ShotGun" Nelson'>
反之亦然:
<p title="John 'ShotGun' Nelson">
反斜杠(\
)转义字符将特殊字符转换为字符串字符。
如果中间有额外的符号,您可以在它们之前使用 \
反斜杠,这样它们就不会干扰代码并被视为这样的符号:
<p title="John \'ShotGun\' Nelson you\'re a good\bad person">
它将显示如下:
John 'ShotGun' Nelson 你是 good\bad 人