我正在尝试为表单中的“其他”字段构建组合单选/文本输入。
<input id="artist" type="radio" name="artist" value="Other">
<input id="other-artist" type="text" name="other_artist" placeholder="Other Artist"/>
我不知道如何在文本输入内部单击并选择 radio 。我尝试将文本输入包装在标签中,但这没有用。
最佳答案
你可以像这样添加一个onclick事件来取消输入和检查 radio 。
<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;
}
希望这对您有所帮助。
关于javascript - 如何将单选输入与文本输入相结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47851209/