Jquery datepicker popup not closing on select date in IE8

前端 未结 10 1349
逝去的感伤
逝去的感伤 2020-12-15 05:46

I\'ve got a web form with a start date field. I\'ve tied a jquery datepicker to the txt field. Now when I choose a date in FF, the selected date is populated in the text box

10条回答
  •  青春惊慌失措
    2020-12-15 06:38

    As a date is selected, the datepicker triggers the change event on the INPUT element, but the ASP.Net validator picks up the click event instead, with the source an A element, and tries to find the validators on that A element, instead of the INPUT. This can be observed by inspecting event.srcElement inside the validator's ValidatorOnChange function. In browsers other than IE, event.type is 'change' and event.target is correctly the INPUT.

    While the no-op function onSelect: function() { } prevents the error, by overriding the .change() built-in to the datepicker's default onSelect, it also prevents the validators from triggering. Here's a work-around for both:

    onSelect: function() {
      this.fireEvent && this.fireEvent('onchange') || $(this).change();
    }
    

    This uses the normal .change() trigger except on IE, where it's required to use .fireEvent to get the event object to be associated with the change and not the click.

提交回复
热议问题