这是我的代码:
function figureSelector () {
document.getElementById("rook").onclick = function () {
curr = '"rook"';
};
};
function moveLine(){
document.getElementById("upButton").onclick = function() {
document.getElementById(curr).style.top = document.getElementById(curr).offsetTop - getPix() * 62 + "px";
counter= counter + getPix();
};
我想写一个棋子移动的通用函数。我想要的只是,当一个人点击棋子,然后按下向上按钮时,它必须上升。
最佳答案
是的,你可以使用字符串变量:
HTML:
<div id="name" style="width:300px;height:300px;background:red"></div>
javascript:
var b = 'name';
document.getElementById(b).innerHTML = 'none';
关于javascript - 我可以在 document.getElementById() 中使用字符串变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22068387/