以 meteor 教程中的表格为例
<form>
<input type="text" name="playerName">
<input type="submit" value="Add Player">
</form>
我可以使用event.target.playerName.value来访问输入的值。
但是,如果我的输入名称是动态生成的,我如何访问它?
for (i = 1; i <= 3; i++) {
console.log(event.target.playerName+i.value)
}
最佳答案
例如,您也可以使用数组表示法引用对象变量
for (i = 1; i <= 3; i++) {
console.log(event.target[playerName+i].value)
}
关于javascript - Meteor Form 使用动态名称获取输入值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39947766/