最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - e.target.value on an input field ReactJs, how does it work? - Stack Overflow

programmeradmin7浏览0评论

.html

I'm at the end of this tutorial and I'm just not understanding how e.target.value works. Walk through the end of this tutorial and see the sample code that there is please. I'm newbie both to React and Javascript.

https://facebook.github.io/react/docs/thinking-in-react.html

I'm at the end of this tutorial and I'm just not understanding how e.target.value works. Walk through the end of this tutorial and see the sample code that there is please. I'm newbie both to React and Javascript.

Share Improve this question edited Aug 10, 2017 at 23:51 halfer 20.4k19 gold badges108 silver badges201 bronze badges asked Aug 10, 2017 at 23:19 Diogo MatiasDiogo Matias 2131 gold badge2 silver badges7 bronze badges 4
  • 14 e is the event, which in this case is change, target is the element that triggered the event, which in this case is the input, and value is the value of the input element – JJJ Commented Aug 10, 2017 at 23:24
  • 1 I recommend to read quirksmode.org/js/introevents.html . – Felix Kling Commented Aug 10, 2017 at 23:29
  • 1 A slightly confusing thing worth researching is the difference between e.target and e.currentTarget . Reading about the difference may help your understanding. – Shammoo Commented Aug 11, 2017 at 8:49
  • Thank you @Josan , it's more clear now. Thanks for the documentation Felix, I will read it. I will also see that Shammoo. Thanks everybody! – Diogo Matias Commented Aug 11, 2017 at 16:25
Add a comment  | 

3 Answers 3

Reset to default 14

The e is the argument of an event handler you attach to a certain event on a certain component... in this case the onFilterTextInput event. Events are objects with certain properties, and e.target almost always represents a DOM element.

Thus e.target.value is the value property of some DOM element, in this case that means the text entered in the search input.

When you need to handle multiple controlled input elements, you can add a name attribute to each element and let the handler function choose what to do based on the value of event.target.name. By React DOC

So, 'e' stands for event and target is the element that triggered the event. I find pretty useful this explanation about the difference between event.target and event.currentTarget at W3Schools

发布评论

评论列表(0)

  1. 暂无评论