我要更改此:
function KeyChange2() {
var uI3 = dS229.value;
mK1.className = uI3;
mK2.className = uI3;
mK3.className= uI3;
}
像这样:
function KeyChange2() {
var uI3 = dS229.value;
var x = className;
mK1.x = uI3;
mK2.x = uI3;
mK3.x = uI3;
}
dS229.value代表输入
最佳答案
您可以使用方括号符号代替点符号来访问属性:
function KeyChange2() {
var uI3 = dS229.value;
var x = 'className';
mK1[x] = uI3;
mK2[x] = uI3;
mK3[x] = uI3;
}
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
关于javascript - 我想知道我是否可以在函数中用字母交换className,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37955700/