[英]Meteor Form getting input value with dynamic name
以流星教程中的这种形式为例
<form>
<input type="text" name="playerName">
<input type="submit" value="Add Player">
</form>
我可以使用event.target.playerName.value来访问输入的值。
但是,如果我的输入名称是动态生成的,该如何访问它?
例如。 我有playerName1,playerName2,playerName3,并且我想使用for循环来访问它们。
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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.