选择元素时jQuery错误

时间:2016-06-17 07:21:14

标签: javascript jquery

尝试使用所选元素的ID时出错。以下是该功能,尝试使用this代替document.GetElementById()时发生错误。

(function($) {

        $.fn.multimap = function( options ) {



            // This is the easiest way to have default options.
            var settings = $.extend({
                // These are the defaults.
                locations: [
                    ['Address Title', 'Add Address Here', {lat: 53.008756, lng: -2.181422}]
                ],
                iconSize: { width: 70, height: 70 },
                zoom: 10,
                mapType: 'ROADMAP'

            }, options );

            var map;
            var bounds = new google.maps.LatLngBounds();

            // Override handles
            var i_iconSize = settings.iconSize;
            if (settings.iconSize.constructor !== Object) { 
                i_iconSize = { width: settings.iconSize, height: settings.iconSize };
            }


            function initialize() {
                var lat = parseFloat(settings.locations[0][2]['lat']);
                var lng = parseFloat(settings.locations[0][2]['lng']);
                var i_mapType;

                switch(settings.mapType) {
                    case "ROADMAP":
                        i_mapType = google.maps.MapTypeId.ROADMAP;
                        break;
                    case "SATELLITE":
                        i_mapType = google.maps.MapTypeId.SATELLITE;
                        break;
                    case "HYBRID":
                        i_mapType = google.maps.MapTypeId.HYBRID;
                        break;
                    case "TERRAIN":
                        i_mapType = google.maps.MapTypeId.TERRAIN;
                        break;
                }

                map = new google.maps.Map(
                this, {
                    // Initial center point, changes ones the markers are added though
                    center: new google.maps.LatLng(lat,lng),

                    // This doesn't seme to work, seems to just scale to fit all markers in at the moment
                    zoom: settings.zoom,

                    // Change the map type, not sure what the others are called
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                });

                for (i = 0; i < (settings.locations).length; i++) {
                    createMarker(settings.locations, i);
                }
            }

错误:

  

未捕获的TypeError:无法执行&#39; getComputedStyle&#39; on&#39; Window&#39;:参数1的类型不是&#39;元素&#39;。

这是对函数的调用:

$("#map_canvas").multimap({ });

0 个答案:

没有答案