jQuery:启用/禁用日期选择器 [英] jQuery: enabling/disabling datepicker

查看:28
本文介绍了jQuery:启用/禁用日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 php 文件中,我想使用 jQuery Datepicker.

In my php-file, I want to use the jQuery Datepicker.

当我的文件加载时,我创建了禁用的日期选择器.

When my file loads, I create the Datepicker disabled.

然后,当我的 php 文件(它是一个表单)中的一个特殊字段被填充时,我想启用日期选择器.

Then, when a special field in my php-file (it is a form) is filled, I want to enable the Datepicker.

所以,最初我的 Datepicker 看起来像这样:

So, initially my Datepicker looks like this:

$("#from").datepicker({
    showOn: "both",
    buttonImage: "calendar.gif",
    buttonImageOnly: true,
    buttonText: "Kalender",
    showAnim: "drop",
    dateFormat: "dd.mm.yy",
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    showWeek: true,
    firstDay: 1,
    dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
    weekHeader: "KW",
    disabled: true,
    onClose: function(selectedDate) {
        $("#to").datepicker("option", "minDate", selectedDate);
    }
});

这很好用,目前没问题.问题来了,当我想禁用该字段时.

This works just fine, no problem so far. The problem comes, when I want to disable the field.

如果填写了特殊字段,我调用 $("#from").datepicker('enable');

If a special field is filled, I call $("#from").datepicker('enable');

这也很好用,但现在我想再次禁用它,如果我提到的特殊字段再次为空.

This also works fine, BUT now I want to disable it again if the special field I mentioned it empty again.

然后我使用$("#from").datepicker('disable'); 并且字段本身是灰色的,但我仍然可以使用该字段输入值,日历弹出甚至框旁边的日历图像也是可点击的.

Then I use $("#from").datepicker('disable'); and the field itself is grayed, but I can still use the field to enter values, the calender pops up and even the calender-image next to the box is clickable.

有人知道为什么会这样吗?我错过了什么吗?

Anyone has an idea why this is the case? Am I missing something?

推荐答案

$("#from").datepicker('disable'); 应该可以,但你也可以试试这个:

$("#from").datepicker('disable'); should work, but you can also try this:

$( "#from" ).datepicker( "option", "disabled", true );

这篇关于jQuery:启用/禁用日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆