React-js ignores label's 'for' attribute

假装没事ソ 提交于 2019-12-04 08:46:39

问题


I know that for 'class' we must use className, but how do i get react to preserve 'for' attribute?

The following:

<label for="recipient-name" className="control-label">Recipient:</label>

is rendered as:

<label class="control-label">Recipient:</label>

on an unrelated note, i find it annoying that i can not change attributes using chrome's console when using React. is there a way around that? for example if i inspect the rendered element and add the 'for' attribute manually, it disappears when i click away from that control (presumably because react re-renders the control i'm guessing)


回答1:


You must use htmlFor attribute instead

<label htmlFor="recipient-name" className="control-label">Recipient:</label>


来源:https://stackoverflow.com/questions/29161330/react-js-ignores-labels-for-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!