React-js忽略label的'for'属性 [英] React-js ignores label's 'for' attribute

查看:56
本文介绍了React-js忽略label的'for'属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道对于'class'我们必须使用className,但是如何保留'for'属性?

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

以下内容:

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

呈现为:

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

在一张不相关的笔记上,我发现在使用React时无法使用chrome的控制台更改属性很烦人。那有什么方法吗?例如,如果我检查渲染的元素并手动添加'for'属性,当我点击该控件时它会消失(大概是因为反应重新渲染我正在猜测的控件)

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)

推荐答案

您必须使用 htmlFor 属性

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

这篇关于React-js忽略label的'for'属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆