美文网首页
在react中label标签不能使用for关键字——Warnin

在react中label标签不能使用for关键字——Warnin

作者: EchoHi | 来源:发表于2020-06-07 18:06 被阅读0次

在react中label标签不能使用for关键字

报错警告:
Warning: Invalid DOM property for. Did you mean htmlFor?

错误写法:

<div className="radioItem">
      <input type="radio" id="curEntrust" />
      <label for="curEntrust">当前委托</label>
</div>

应改为:

<div className="radioItem">
      <input type="radio" id="curEntrust" />
      <label htmlFor="curEntrust">当前委托</label>
</div>

在使用React时,不能在JSX中使用for关键字,因为这是一个javascript关键字(JSX是javascript,所以像for和class这样的词不能使用,因为它们有其他特殊含义!)

相关文章

网友评论

      本文标题:在react中label标签不能使用for关键字——Warnin

      本文链接:https://www.haomeiwen.com/subject/uqactktx.html