Jquery date picker not working with Google Map InfoWindow

♀尐吖头ヾ 提交于 2019-12-12 17:40:25

问题


Jquery ui datepicker is working outside the map but in the map the jquery ui datepicker not working.

Any Idea what could be wrong?

Code:

var html = "<table width='250px' height='300px'>" +
                 "...." +
                 "<tr><td>Url:...." +
                 "<tr><td>Date:</td> <td><input type='text' id='datepicker'/> </td> </tr>" +               
                 "<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr></table>";

    infowindow = new google.maps.InfoWindow({
     content: html
    });

I can save all the form information from the map. But the datepicker is not working inside the map.

And the event listener i am using:

google.maps.event.addListener(map, "click", function(event) {
    marker = new google.maps.Marker({
      position: event.latLng,
      map: map
    }); 
    google.maps.event.addListener(marker, "click", function() {
        $( "#datepicker" ).datepicker();
      infowindow.open(map, marker);
    });
});

Anyone have any idea?

image: http://postimg.org/image/oe40y960z/


回答1:


use the domready-event of the infowindow to create the datepicker.

Before the domready-event the table hasn't been injected into the document and #datepicker may not be accessed by jQuery.

Another option: apply the datepicker directly before you set the content:

infowindow = new google.maps.InfoWindow({
 content: $(html).find('#datepicker').datepicker().end()[0]
});

Note: when the UI will be covered by the map set the zIndex:

#ui-datepicker-div{z-index:1000 !important}



回答2:


You have to pass datepicker in domready

Below is the code

 infowindow.addListener('domready', function() {
        $('.datepicker').fdatepicker({
            pickTime: true,
        });
    });


来源:https://stackoverflow.com/questions/21661703/jquery-date-picker-not-working-with-google-map-infowindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!