如果单击“其他”单选按钮,如何启用输入类型=文本。
<tr><td><font color='red' size='3'>*</font>CIVIL STATUS</td><td>:</td><td><input type='radio' name='civstat' value='Single' required='required'> Single
<br><input type='radio' name='civstat' value='Married' required='required'> Married
<br><input type='radio' name='civstat' value='Annuled' required='required'> Annuled
<br><input type='radio' name='civstat' value='Widowed' required='required'> Widowed
<br><input type='radio' name='civstat' value='Seperated' required='required'> Seperated
<br><input type='radio' name='civstat' required='required' onclick='civstattxton()'> Others,
please specify here<input type='text' name='civstat' id='civstaton'></td>
</tr>
答案 0 :(得分:1)
您可以使用javascript根据每个输入的onclick事件禁用/启用输入。它很乱,但完成工作:
<tr><td><font color='red' size='3'>*</font>CIVIL STATUS</td><td>:</td><td><input type='radio' name='civstat' value='Single' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Single
<br><input type='radio' name='civstat' value='Married' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Married
<br><input type='radio' name='civstat' value='Annuled' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Annuled
<br><input type='radio' name='civstat' value='Widowed' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Widowed
<br><input type='radio' name='civstat' value='Seperated' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Seperated
<br><input type='radio' name='civstat' required='required' onclick='document.getElementById("civstaton").removeAttribute("disabled");'> Others,
please specify here<input type='text' name='civstat' id='civstaton' disabled></td>
</tr>
以下是演示:JSBIN
我建议使用像jQuery这样的库将事件处理程序附加到单选按钮而不是这个凌乱的内联解决方案。
答案 1 :(得分:0)
<input type='radio' name='civstat' required='required'
onclick='document.getElementById("civstaton").disabled = false'>
Others, please specify here
<input type='text' name='civstat' id='civstaton' disabled>