首先,我要说我知道此站点上至少还有十个其他几乎相同的问题。我看到了所有这些内容,并尝试了许多答案,但问题仍然存在,可能是因为我试图以错误的方式实现答案。无论如何,只要我在一个MAC输入中插入一个字符,它就会失去焦点。接下来是带有所述输入和onChange方法的代码段。
{
user.MACs.map
(
(MAC, index) =>
{
return (
<div className = "singleMAC" key = {"singleMAC"+index}>
<label htmlFor = "MAC">MAC {index+1}</label>
<input
form = "userEdit"
className = "MACInput"
value = {MAC || ""}
placeholder = "MAC"
onChange = {(e) => handleChangeMAC (index, e)}
/>
<button
className = "buttonMACRemove"
type = "button"
onClick = {() => handleRemoveMAC (index)}
>
X
</button>
</div>
);
}
)
}
然后...
function handleChangeMAC (index, e)
{
const values = [...user.MACs];
values[index] = e.target.value;
var newUser = Object.assign ({}, user);
newUser.MACs = values;
setUser (newUser);
}