无线电按钮启用/禁用字段



我有一个带有几组无线电按钮的表格。选择一个单选按钮将使text字段与其相反,并禁用其余的字段。我无法启用该字段。我已经尝试了几乎所有功能(Nextall,NextAll,Nextunit,find,findall,最接近...),但可能无法正确使用它们。

这是一个只有一组按钮的测试:http://jsfiddle.net/qtsek/

也在页面上加载一些广播按钮,我必须运行什么才能禁用其余的(未检查字段)?

谢谢

由于您的元素具有类属性,您可以使用类Selector选择它们,用于启用/禁用表单元素,您可以使用prop方法。

$("body").on("click", "input[type='radio']", function() {
    $('.fieldSelector').prop('disabled', true);
    $(this).closest('tr').find('.fieldSelector').prop('disabled', false)
});

http://jsfiddle.net/afrdj/

jsfiddle

$("body").on("click", "input[type=radio]", function() {
   $(this).closest("table").find("input[type=text]").prop("disabled", true);
    $(this).closest("tr").find("input[type=text]").prop("disabled", false);
});​

您可以根据HTML添加/修改选择器。

此外,我不确定我会把活动听众放在身体上。我认为,如果元素在整个页面生命周期中都在DOM中,我会更喜欢这样的东西。(最初是在页面上所讨论的元素吗?)

$("input[type=radio]").on("click", function() {//you can change input[type=radio] to any other selector that you have already used
   $(this).closest("table").find("input[type=text]").prop("disabled", true);
    $(this).closest("tr").find("input[type=text]").prop("disabled", false);
});​

最新更新