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

I have this piece of code that uses jquery datepicker and jquery masked input.jQuery(function($) {$(doc

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745424735a4627122.html

相关推荐

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

    I have this piece of code that uses jquery datepicker and jquery masked input.jQuery(function($) {$(doc

    13小时前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信