for (let i = 1; i < 10; i++) { var b = {}; b['fruit_' + i] =** $("input[name=clmnt"+i"]").val();** alert(b['fruit_' + i]); }
如何在JavaScript中动态地使用按名称调用?下面是我正在尝试的。
xmd2e60i1#
const object = { func1() { console.log('You called func1!'); }, func2() { console.log('You called func2!'); } }; const methodName = 'func1'; object[methodName](); // Output: "You called func1!"
1条答案
按热度按时间xmd2e60i1#