标签: DOM属性

2 个内容

动态(2)

E
Elliot Yang
公开

How to use React label element?

If you try to render a <label> element bound to a text input using the standard for attribute, then it produces HTML missing that attribute and prints a warning to the console.
js
1<label for={'user'}>{'User'}</label>
2<input type={'text'} id={'user'} />
Since for is a reserved keyword in JavaScript, use htmlFor instead.
js
1<label htmlFor={'user'}>{'User'}</label>
2<input type={'text'} id={'user'} />
浏览:244点赞:0
E
Elliot Yang
公开

React v16 support custom DOM attributes.
In the past, React used to ignore unknown DOM attributes. If you wrote JSX with an attribute that React doesn't recognize, React would just skip it.
For example, let's take a look at the below attribute:

js
1<div mycustomattribute={'something'} />

Would render an empty div to the DOM with React v15:

html
1<div />

In React v16 any unknown attributes will end up in the DOM:

html
1<div mycustomattribute='something' />
浏览:279点赞:0