0

仅当单击“其他”单选按钮时,如何启用输入类型 = 文本。

<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>
4

2 回答 2

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 之类的库将事件处理程序附加到您的单选按钮,而不是使用这种凌乱的内联解决方案。

于 2013-05-03T02:12:30.720 回答
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>

演示

于 2013-05-03T02:11:56.080 回答