jQuery:启用/禁用日期戳 [英] jQuery: enabling/disabling datepicker

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

问题描述

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

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

当我的文件加载时,我创建禁用Datepicker。

When my file loads, I create the Datepicker disabled.

然后,当我的php文件(它是一个表单)中的一个特殊字段被填充时,我想启用Datepicker。

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.

如果一个特殊字段被填充,我调用$ $ $ $ $ $$。 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天全站免登陆