英文:
I want to submit two form data by clicking on create button how can i do so
问题
我正在尝试在单击“创建”按钮时同时接收表单数据。
英文:
I am trying to Recieve both form data in single click which is create button.
答案1
得分: 0
我假设你正在使用 reactjs
并且了解 useRef
。你可以使用 useRef
来引用来自不同表单的这两个提交按钮。首先,你需要创建一个变量
const buttonRef = useRef()
现在,你需要将 ref={buttonRef}
添加为这两个按钮标签的属性。最后,你需要添加一个触发这两个按钮点击的函数。你可以将 onClick
属性添加到“Create”按钮上。你可以将以下内容添加到“Create”按钮上:onClick={() => buttonRef.current.click()}
。
这些步骤将允许你提交两个表单,但不会将两个表单数据合并在一起。
英文:
I assume you're using reactjs
and know useRef
. You can use useRef
to reference those two submit buttons from different forms. First you need to create a variable
const buttonRef = useRef()
Now you have to add ref={buttonRef}
to both of those button tags as an attribute. Lastly, you have to add a function that triggers those button clicks. You can add onClick
attribute to Create button. You can add this to Create button onClick={() => buttonRef.currentRef.click()}
.
These steps will let you submit two form. But won't merge two form data into one.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论