当单击复选框#securityCl
时,此代码段成功显示文本输入#typeOther
。但是,如果用户切换到另一个单选按钮,或者通过再次单击#securityCl
复选框禁用输入,为了避免提交不需要的文本,我想隐藏并清除#typeOther
文本输入。当复选框被禁用时显示/隐藏文本输入
HTML:
<table>
<tr>
<td>
<input type="checkbox" id="securityCl" name="securityCL">
<label for="securityCl">Security Clearance - Type:</label>
</td>
</tr>
<tr>
<td class="indent">
<input type="radio" id="typeTsSci" name="securityType" disabled="disabled">
<label for="typeTsSci">TS/SCI</label>
</td>
<td>
<input type="radio" id="typeS" name="securityType" disabled="disabled">
<label for="typeS">S</label>
</td>
</tr>
<tr>
<td class="indent">
<input type="radio" id="typeTs" name="securityType" disabled="disabled">
<label for="typeTs">TS</label>
</td>
<td>
<input type="radio" id="typeOther" name="securityType" disabled="disabled">
<label for="typeOther">Other:</label><br>
</td>
<td>
<input type="text" id="otherText" name="securityType" disabled="disabled">
</td>
</tr>
</table>
而且这里是我的jQuery:
$(function() {
var hide = $('#otherText').hide();
$('#securityCl').click(function() {
$('input[name="securityType"]').prop('disabled', !this.checked);
$('#typeOther').click(function() {
$(hide).show();
});
});
});
那么问题是什么?它没有做你期望的事情?你为什么要嵌套你的处理程序?每次secureCl被点击后,另一个事件处理程序将在securityType上注册。 – 2013-03-14 20:47:24
你在期待'$('#typeOther')。click(function()...'为你做什么? – Hoopdady 2013-03-14 20:47:32
@EliGassert我在嵌套我的处理程序,因为我还在学习做和不该做的事JS。j08691的答案确实是我正在寻找的东西,有没有更好的方法来处理这个问题? – 2013-03-14 20:53:15