How to access custom attributes from event object in React?

前端 未结 15 2070
不思量自难忘°
不思量自难忘° 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 10:15

    I do not know about React, but in the general case you can pass custom attributes like this:

    1) define inside an html-tag a new attribute with data- prefix

    data-mydatafield = "asdasdasdaad"
    

    2) get from javascript with

    e.target.attributes.getNamedItem("data-mydatafield").value 
    

提交回复
热议问题