Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 禁用/启用日期选择器复选框单击_Jquery_Datepicker - Fatal编程技术网

Jquery 禁用/启用日期选择器复选框单击

Jquery 禁用/启用日期选择器复选框单击,jquery,datepicker,Jquery,Datepicker,这是我的密码: $("#myCheckBox").click(function () { if (!$(this).is(':checked')) { $('#txtDateFrom').attr('readonly', true); $('#txtDateTo').attr('readonly', true); $('#txtDateFrom').val('01/01/2012');

这是我的密码:

$("#myCheckBox").click(function () {
        if (!$(this).is(':checked')) {
            $('#txtDateFrom').attr('readonly', true);
            $('#txtDateTo').attr('readonly', true);
            $('#txtDateFrom').val('01/01/2012');
            $('#txtDateTo').val('31/12/2012');
            $('#txtDateFrom').datepicker(this.checked ? "disable" : "disable");
            $('#txtDateTo').datepicker(this.checked ? "disable" : "disable");
        }
        else {
            $('#txtDateFrom').attr('readonly', false);
            $('#txtDateTo').attr('readonly', false);
            $('#txtDateFrom').datepicker(this.checked ? "disable" : "enable");
            $('#txtDateTo').datepicker(this.checked ? "disable" : "enable");
            $('#txtDateFrom').datepicker({ dateFormat: 'dd/mm/yy' });
            $('#txtDateTo').datepicker({ dateFormat: 'dd/mm/yy' });
        }
    });
取消勾选复选框并再次选中后,文本框仍处于禁用状态。为什么?

尝试
.removeAttr()
而不是通过
.attr()
将readonly设置为false。例如:

$('#txtDateFrom').removeAttr('readonly');
尝试
.removeAttr()
而不是通过
.attr()
将readonly设置为false。例如:

$('#txtDateFrom').removeAttr('readonly');

这可能是您的问题:

$('#txtDateFrom').datepicker(this.checked ? "disable" : "disable");
$('#txtDateTo').datepicker(this.checked ? "disable" : "disable");
应该是这样的:

$('#txtDateFrom').datepicker(this.checked ? "disable" : "enable");
$('#txtDateTo').datepicker(this.checked ? "disable" : "enable");

这可能是您的问题:

$('#txtDateFrom').datepicker(this.checked ? "disable" : "disable");
$('#txtDateTo').datepicker(this.checked ? "disable" : "disable");
应该是这样的:

$('#txtDateFrom').datepicker(this.checked ? "disable" : "enable");
$('#txtDateTo').datepicker(this.checked ? "disable" : "enable");