The problem of React getting attributes. Why do you use e.target.index to get undefined??

<div className="form-group">
  <label className="col-md-2 control-label"></label>
    <div className="col-md-5">
      <input type="text" className="form-control"  placeholder=""
             name="productName" value={this.state.name}
             onChange={(e)=>{this.onChange(e)}}/>
   </div>
</div>
onChange(e){
   console.log(e.target.value);
//e.target.getAttribute("value")  }

e.target:



e.target:

Mar.09,2021

e.target gets a DOM element.
DOM there are two types of related operations:

  1. Property
  2. Attribute

Attribute represents attr1 and attr2 in < tag attr1 attr2 > , and needs to be obtained through getAttribute .
and Property are some special attribute values of DOM, which can be obtained directly by .XXX .
commonly used Property have:

  1. className
  2. htmlFor
  3. style
  4. value

corresponding Attribute has:

  1. class
  2. for
  3. style
  4. value

this explains why target.value can be obtained while target.index cannot, because value is Property (only misunderstood because it has the same name as Attribute ), while index is not, so it can only be obtained through getAttribute .

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b373c0-2c05c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b373c0-2c05c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?