How do I reset the datepicker calendar values?.. The min and max date restrictions?

问题是,当我清除日期时(通过删除文本框值),以前的日期限制仍然适用.

我一直在整理这documentation个,但没有一个是解决方案.我也无法在SO/Google搜索中找到快速修复

http://jsfiddle.net/CoryDanielson/tF5MH/


Solution:

// from & to input textboxes with datepicker enabled
var dates = $("input[id$='dpFrom'], input[id$='dpTo']");

// #clearDates is a button to clear the datepickers
$('#clearDates').on('click', function(){
    dates.attr('value', '');
    dates.each(function(){
        $.datepicker._clearDate(this);
    });
});​​

_.clearDate()是DatePicker对象的私有方法.在jQueryUI的网站上的公共API中找不到它,但它的工作方式很有魅力.

推荐答案

I was trying to accomplish this very thing, that is, empty the datepicker so that filters entered by the user could be removed. Googling a bit I found this sweet piece of code:

You can add the clear feature even on read only fields. Just add the following code to your datepicker:

}).keyup(function(e) {
    if(e.keyCode == 8 || e.keyCode == 46) {
        $.datepicker._clearDate(this);
    }
});

People will be able to highlight (even Read Only fields) and then use backspace or delete key to remove the date using _clearDate function.

Source

Jquery相关问答推荐

逐个交换图像

点击和touch 事件之间的jQuery冲突解决方法

Visual Studio - 将文本粘贴到 cshtml 中会删除文本

如何使用 jQuery 的 drop 事件上传从桌面拖动的文件?

当输入值以编程方式更改时触发更改事件?

使用 jQuery 和 HTML 导出为 CSV

jquery - 单击事件不适用于动态创建的按钮

以ajax方式在rails 3中提交表单(使用jQuery)

禁用 Android 网页中输入焦点的zoom

如何获取 onclick 调用对象?

jquery变量语法

在不丢失光标位置的情况下更新输入值

jQuery - 多个 :not Select 器

CORS POST 请求可以使用纯 JavaScript,但为什么不使用 jQuery?

如何使用 javascript (jquery) 将整数值添加到返回字符串的值中?

检测用户是否创建了滚动事件

如何在 Bootstrap 中创建切换按钮

在事件中使用 jQuery 获取被点击的元素?

使用中键触发 onclick 事件

在页面加载之间保持变量