问题
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