使用函数的参数名称作为字符串

时间:2021-03-21 17:56:37

标签: javascript

如何将函数的参数名称作为字符串传递给嵌套函数? 我有 2 个变量,假设 name1=5 和 name2=10,我想创建一个函数,该函数将使用这些变量值之一,并在其他地方使用变量名作为字符串。

var name1 = 5
var name2 = 10

function func(arg){
    document.getElementById("a1").innerText = arg //that works fine, it sets the text as 5 or 10
    document.getElementById("arg" + "some string").innerText = "some other string" // here i need the argument's name as string, for example "name1".
}

我希望我的问题是可以理解的,英语不是我的默认语言。

0 个答案:

没有答案
相关问题