我的按钮如何在每个新的添加部分下移动?现在,它放在所有部分上方
如何修改代码以获取动态+添加invitee
按钮,每次添加字段时都会向下移动最后一部分?目前,它出现在所有块上。
export default function App() {
const [menu, setMenu] = useState("");
return (
<>
<button type="button" onClick={addInvitee}>
+Add Invitee
</button>
<form onSubmit={handleSubmit}>
{invited.map(({ age, email, id, location, name }, index) => (
<div key={id}>
<div className="grid grid-cols-3 gap-5">
<label className="mr-3 h-6 text-md font-bold">
Names:
<input
type="text"
value={name}
placeholder="Names"
name="name"
onChange={updateInvitee(id)}
/>
</label>
...
{!!index && (
<button type="button" onClick={() => removeInvitee(id)}>
Remove
</button>
)}
</div>
</div>
))}
</form>
</>
);
}
这是我的:
代码
How can I modify my code in order to get a dynamic +Add Invitee
button which will move down the last section each time you add fields? For now, it appears above all blocks.
export default function App() {
const [menu, setMenu] = useState("");
return (
<>
<button type="button" onClick={addInvitee}>
+Add Invitee
</button>
<form onSubmit={handleSubmit}>
{invited.map(({ age, email, id, location, name }, index) => (
<div key={id}>
<div className="grid grid-cols-3 gap-5">
<label className="mr-3 h-6 text-md font-bold">
Names:
<input
type="text"
value={name}
placeholder="Names"
name="name"
onChange={updateInvitee(id)}
/>
</label>
...
{!!index && (
<button type="button" onClick={() => removeInvitee(id)}>
Remove
</button>
)}
</div>
</div>
))}
</form>
</>
);
}
Here is my:
code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您只需要按下表格下的按钮即可。
另外,您可以样式的按钮或用DIV包装,以进行更复杂的样式,以从您共享的照片中实现示例。
这是一个工作示例的Alink: codesandbox
To achieve that you just need to take the button down under the form.
also you can style the button or wrap it with a div for more complex styling to achieve the example from the photo you shared.
here is alink for a working example: codesandbox