0

我想要完成的是:

当用户单击第一个Open until Filled选项时,请禁用日期输入。但是当用户点击第二个打开直到单选按钮时。启用日期输入。

截至目前,我似乎无法让它工作。它似乎完全跳过了我的检查。我错过了什么吗?

$(function() {
    if ($('input#id_open:checked').length > 0) {
        alert("please fill in the date");
        $('input[name=end_date]').attr('disabled', false);
    }
});

我在这里做了一个小提琴来说明我的意思。

提前感谢您的帮助!

4

2 回答 2

2

工作示例:http: //jsfiddle.net/8KggV/5/

$(function() {
    $('input').click(function(){
    if ($('#id_open:checked').length > 0) {
        $('input[name=end_date]').attr('disabled', false);
    }
        else{
            $('input[name=end_date]').attr('disabled', true);        
        }
    })
});
于 2013-03-27T20:23:08.177 回答
1

使用 jQuery 时,为了检测控件是否被选中,我使用 is 方法。您也不需要检查长度,因为 is 方法返回一个布尔值。

$(function() {
    if ($('input#id_open').is(':checked')) {
        alert("please fill in the date");
        $('input[name=end_date]').attr('disabled', false);
    }
});
于 2013-03-27T20:22:40.390 回答