[英]How to fix "A form label must be associated with a control" ? ESlint
I have read that htmlFor needs to be added to fix this error, but even with this piece of code, ESlint gives me an error.我已阅读需要添加 htmlFor 来修复此错误,但即使使用这段代码,ESlint 也会给我一个错误。 How can I fix this?
我怎样才能解决这个问题?
<input readOnly type="radio" name="slider-2" id="s1-2" checked />
<input readOnly type="radio" name="slider-2" id="s2-2" />
<input readOnly type="radio" name="slider-2" id="s3-2" />
<label type="text" htmlFor="s1-2" id="slide1-2">
<div className="slider-image">
<img src={SecendQadroFirst} alt="qadro" />
</div>
</label>
<label htmlFor="s2-2" id="slide2-2">
<div className="slider-image">
<img src={SecendQadroSecend} alt="qadro" />
</div>
</label>
<label htmlFor="s3-2" id="slide3-2">
<div className="slider-image">
<img src={SecendQadroThird} alt="qadro" />
</div>
</label>
The attribute you want in the <label>
element is simply for
, and the value must be the id of the <input>
element it is associated with. <label>
元素中需要的属性只是for
,其值必须是与其关联的<input>
元素的 id。 The input should be after the </label>
closing tag输入应该在
</label>
结束标记之后
<label type="text" for="s1-2" id="slide1-2">
<div className="slider-image">
<img src={SecendQadroFirst} alt="qadro">
</div>
</label>
<input readOnly type="radio" name="slider-2" id="s1-2" checked>
<label for="s2-2" id="slide2-2">
<div className="slider-image">
<img src={SecendQadroSecend} alt="qadro">
</div>
</label>
<input readOnly type="radio" name="slider-2" id="s2-2">
<label for="s3-2" id="slide3-2">
<div className="slider-image">
<img src={SecendQadroThird} alt="qadro">
</div>
</label>
<input readOnly type="radio" name="slider-2" id="s3-2">
只需写for
而不是htmlFor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.