How to access custom attributes from event object in React?

前端 未结 15 2030
不思量自难忘°
不思量自难忘° 2020-11-27 09:27

React is able to render custom attributes as described at http://facebook.github.io/react/docs/jsx-gotchas.html:

If you want to use a custom attribut

15条回答
  •  粉色の甜心
    2020-11-27 09:51

    Here's the best way I found:

    var attribute = event.target.attributes.getNamedItem('data-tag').value;
    

    Those attributes are stored in a "NamedNodeMap", which you can access easily with the getNamedItem method.

提交回复
热议问题