这是我能看到的最简单的方法,如果我错了,请纠正我!
<form name="fruitForm" method="post" action="other-post.php">
<label><input type="radio" name="fruit" value="apple" onClick="regularFruit()">apple</input></label>
<label><input type="radio" name="fruit" value="orange" onClick="regularFruit()">orange</input></label>
<label><input type="radio" name="fruit" value="lemon" onClick="regularFruit()">lemon</input></label>
<label onClick="otherFruit()">
<input type="radio" name="fruit" id="other_fruit" value="other" >or other fruit:</input>
<input type ="text" name="other" id="other_text"/></label>
<input type="submit" value="Submit">
</form>
<script>
function otherFruit(){
a=document.getElementById('other_fruit');
a.checked=true;
}
function regularFruit(){
a=document.getElementById('other_text');
a.value="";
}
</script>
在标签包含单选和文本字段的情况下,文本字段检查“其他”单选,并将“其他”的值作为在该字段中输入的值发送。然后再次检查单选按钮会清除文本字段