我刚开始学习 JavaScript,遇到了一个小问题。
var id;
function replay(id){
document.getElementById(id).innerHTML='<form action="./replay.php?uid= method="get"><hr><input type="submit" name="qpost" class="replay_key" value="Post" style="background-color: #a9d22c;"></form>';
}
我想在后面添加变量“id”,但无法弄清楚语法
<form action="./replay.php?uid=
最佳答案
像这样:
document.getElementById(id).innerHTML='<form action="./replay.php?uid=' + id + '" method="get"><hr><input type="submit" name="qpost" class="replay_key" value="Post" style="background-color: #a9d22c;"></form>';
本质上你想要:
something = 'string literal' + variableName + 'another string literal';
关于字符串中的 JavaScript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20607874/