Strange behavior of select/dropdown's onchange() JS event when using 'Next' on Mobile Safari Dropdown list item select box

后端 未结 1 742
挽巷
挽巷 2020-11-29 05:13

This is a hard one to articulate and I am new to mobile web development so please bear with me:

On my webpage, I have 3 Nested dropdown lists (Area,

相关标签:
1条回答
  • 2020-11-29 05:17

    I had the same problem on my site. I was able to fix it by manually polling the selectedIndex property on the select control. That way it fires as soon as you "check" the item in the list. Here's a jQuery plugin I wrote to do this:

    $.fn.quickChange = function(handler) {
        return this.each(function() {
            var self = this;
            self.qcindex = self.selectedIndex;
            var interval;
            function handleChange() {
                if (self.selectedIndex != self.qcindex) {
                    self.qcindex = self.selectedIndex;
                    handler.apply(self);
                }
            }
            $(self).focus(function() {
                interval = setInterval(handleChange, 100);
            }).blur(function() { window.clearInterval(interval); })
            .change(handleChange); //also wire the change event in case the interval technique isn't supported (chrome on android)
        });
    };
    

    You use it just like you would use the "change" event. For instance:

    $("#mySelect1").quickChange(function() { 
        var currVal = $(this).val();
        //populate mySelect2
    });
    

    Edit: Android does not focus the select when you tap it to select a new value, but it also does not have the same problem that iphone does. So fix it by also wiring the old change event.

    0 讨论(0)
提交回复
热议问题