最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery datepicker and jquery mask not working - Stack Overflow

programmeradmin2浏览0评论

I have this piece of code that uses jquery datepicker and jquery masked input.

jQuery(function($) {
    $(document).on('click', '#date', function () { 
        var me = $("#date");   
        me.datepicker({
            showOn: 'focus',
            altFormat: "mm/dd/yy",
            dateFormat: "mm/dd/yy",
            minDate: '12/12/2000',
            maxDate: '12/12/2020'
        }).focus();
        me.mask('99/99/9999');
    }).on('select', '#date', function () {
        var me = $("#date");
        me.mask('99/99/9999');
    });
});

JSFiddle

The code uses jquery on because the input element in the application is dynamically added into the page. And the masked input is also registered from select event because user can e to the input by pressing tab from previous input.

It doesn't work on Firefox 31, but it works fine on Chrome 36 and IE 11. When the input field is empty, user should be able to type anything (based on masked filter) in the input element.

Kindly suggest me what's wrong with the code.

I have this piece of code that uses jquery datepicker and jquery masked input.

jQuery(function($) {
    $(document).on('click', '#date', function () { 
        var me = $("#date");   
        me.datepicker({
            showOn: 'focus',
            altFormat: "mm/dd/yy",
            dateFormat: "mm/dd/yy",
            minDate: '12/12/2000',
            maxDate: '12/12/2020'
        }).focus();
        me.mask('99/99/9999');
    }).on('select', '#date', function () {
        var me = $("#date");
        me.mask('99/99/9999');
    });
});

JSFiddle

The code uses jquery on because the input element in the application is dynamically added into the page. And the masked input is also registered from select event because user can e to the input by pressing tab from previous input.

It doesn't work on Firefox 31, but it works fine on Chrome 36 and IE 11. When the input field is empty, user should be able to type anything (based on masked filter) in the input element.

Kindly suggest me what's wrong with the code.

Share Improve this question edited Aug 5, 2014 at 10:43 Yuliam Chandra asked Aug 5, 2014 at 10:32 Yuliam ChandraYuliam Chandra 14.7k12 gold badges55 silver badges69 bronze badges 2
  • 1 Try this jsfiddle/6Z2Ws/2 – Aamir Afridi Commented Aug 5, 2014 at 11:05
  • 1 @AamirAfridi, I appreciated the help, but the mask is also required when the input is activated from another input (e.g. pressing tab from previous input), anyway I already solve it, thx – Yuliam Chandra Commented Aug 5, 2014 at 11:06
Add a ment  | 

1 Answer 1

Reset to default 0

Just fixed it by changing the select into focus, I can't remember why I used select in the first place.

jQuery(function($) {
    $(document).on('click', '#date', function () { 
        var me = $("#date");   
        me.datepicker({
            showOn: 'focus',
            altFormat: "mm/dd/yy",
            dateFormat: "mm/dd/yy",
            minDate: '12/12/2000',
            maxDate: '12/12/2020'
        }).focus();
    }).on('focus', '#date', function () {
        var me = $("#date");
        me.mask('99/99/9999');
    });
});

Fixed JSFiddle

发布评论

评论列表(0)

  1. 暂无评论