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".
}
我希望我的问题可以理解,英语不是我的默认语言。
解决方案
推荐阅读
- javascript - 如何取消选中多个选择器并使用js执行减法?
- selenium - 第一类运行的测试方法等于 testng.xml 文件中的测试数量
- java - 如何获取一个月中特定周的开始和结束日期
- flask - Flask-Dash 与用户身份验证的集成
- html - 使用 Multer 在 Nodejs 中上传多个图像
- reactjs - 为什么在部署我的项目后卡住/空白页面?反应路由器 Dom | 参数
- python - 试图绘制大约 10 条线并以不同的方式命名每条线?
- java - 在集成 Razorpay 支付网关期间没有支付?
- reactjs - 如何在从 API 调用收到的响应中打开文件
- python - 对迭代中具有重复元素的字符串进行分区