我正在尝试为表单中的“其他”字段构建组合的广播/文本输入。
<input id="artist" type="radio" name="artist" value="Other">
<input id="other-artist" type="text" name="other_artist" placeholder="Other Artist"/>
我无法弄清楚如何在文本输入内部单击并选择了收音机。我尝试将文本输入包装在标签中,但这不起作用。
你可以添加一个onclick事件来输入并像这样检查收音机。
<input id="artist" type="radio" name="artist" value="Other">
<input id="other-artist" type="text" name="other_artist"placeholder="Other Artist"
onClick="selectRadio()" />
和js
selectRadio = () => {
var radio = document.getElementById("artist");
radio.checked = true;
}
希望这个帮助。