jQuery: enabling/disabling datepicker

前端 未结 18 1098
青春惊慌失措
青春惊慌失措 2020-12-03 06:38

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

When my file loads, I create the Datepicker disabled.

Then, when a special field in my php-file (it is a

18条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-03 07:03

    I have a single-page app in our company intranet where certain date fields need to be "blocked" under certain circumstances. Those date fields have a datepicker binding.

    Making the fields read-only wasn't enough to block the fields, as datepicker still triggers when the field receives focus.

    Disabling the field (or disabling datepicker) have side effects with serialize() or serializeArray().

    One of the options was to unbind datepicker from those fields and making them "normal" fields. But one easiest solution is to make the field (or fields) read-only and to avoid datepicker from acting when receive focus.

    $('#datefield').attr('readonly',true).datepicker("option", "showOn", "off");
    

提交回复
热议问题