假设我有一个函数正在传递一个最初来自 getElementById 的字符串,并且我有一个与该字符串的值同名的对象,有没有办法调用该对象?在从元素的 ID 中获取该值之前,我不会知道我想要哪个对象。
例如:
StartingFunction(SomeID){
someVariable = document.getElementById(SomeID).id
somefuntion(someVariable)
}
someFunction(ElementID){
// need to call Object.Value of whichever object is named the same as the value of
//ElementID here
}
ElementID.Value 显然不起作用,因为 ElementID 只是一个变量,而不是一个对象......