[英]How do I detect in my class component which input value's clicked in functional component?
How do I detect in my class component which <input/>
's value
was clicked in my functional component?如何在我的 class 组件中检测到在我的功能组件中单击了哪个
<input/>
的value
? For example, if the user clicks Yes
, then I want the postIsClicked()
(which's in my class component) function to display that it's indeed detected the Yes
that's been clicked.例如,如果用户单击
Yes
,那么我希望postIsClicked()
(在我的 class 组件中) function 显示它确实检测到了被点击的Yes
。
My attempt consisted of giving a name
to the inputs and then trying to detect is via e.target.name
but it just keeps loggin No has been clicked
in the console regardless of which button I press (Yes or No)我的尝试包括为输入
name
,然后尝试通过e.target.name
进行检测,但它只是保持登录 无论我按下哪个按钮(是或否), No has been clicked
否
What am I doing wrong?我究竟做错了什么?
Pastebin below.粘贴在下面。
The onClick
function can receive the event as argument, so you can access the value by getting e.target.value
. onClick
function 可以接收事件作为参数,因此您可以通过获取e.target.value
来访问该值。
In your case you just need to receive event
as argument to postIsClicked(event)
and then console.log("clicked" + event.target.value)
在您的情况下,您只需要接收
event
作为postIsClicked(event)
的参数,然后console.log("clicked" + event.target.value)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.