javascript - Cannot read property 'addEventListener' of undefined
淡淡烟草味
淡淡烟草味 2017-05-16 13:07:21
0
1
1190

想在百度地图里用addEventListener监听点击marker,结果报错提示Cannot read property 'addEventListener' of undefined

JS代码

var id = <?php echo json_encode($id);?>;
var time = <?php echo json_encode($time);?>;
var height = <?php echo json_encode($height);?>;
var latitude = <?php echo json_encode($latitude);?>;
var longitude = <?php echo json_encode($longitude);?>;
var date = <?php echo json_encode($date);?>;
var speed = <?php echo json_encode($speed);?>;
var rownum = <?php echo json_encode($rownum);?>;

var Point = new Array();

for(var i=0;i<rownum;i++) {
    Point.push(new BMap.Point(longitude[i], latitude[i]));
}

var transPoint = new Array();
var Marker = new Array();

function transcoord() {
    translateCallback = function (data) {
        if (data.status === 0) {
            for(var i=0;i<rownum;i++) {
                transPoint[i]=data.points[i];
                Marker[i]=new BMap.Marker(data.points[i]);
                map.addOverlay(Marker[i]);

            }
        }else{
            //alert(data.status);
        }
    }
    setTimeout(function () {
        var convertor = new BMap.Convertor();
        convertor.translate(Point, 1, 5, translateCallback);
    }, 1000);
}
transcoord();

for(var i=0;i<rownum;i++){

    function ss() {
        var thePoint = transPoint[i];
        var theMarker = Marker[i];
        var theTime = "00:00:00";
        theMarker.addEventListener("click",function(){
            showInfo(this,theTime);
        });
    }
    ss();
}

function showInfo(thisMaker,time){
    var sContent =
        "<ul style='margin:0 0 5px 0;padding:0.2em 0'>"
        +"<li style='line-height: 10px;font-size: 15px;'>"
        +"<span style='width: 50px;display: inline-block;'>000:</span>" + "000" + "</li>"
        +"<li style='line-height: 26px;font-size: 15px;'>"
        +"<span style='width: 50px;display: inline-block;'>time:</span>"+time +"</li>"
        +"</ul>";
    var infoWindow = new BMap.InfoWindow(sContent);  
    thisMaker.openInfoWindow(infoWindow);   
}

大概就是先把一堆GPS坐标转换之后存到数组里,然后放marker设置一个addEventListener使得点击marker的时候可以弹出信息,但是运行的时候提示Cannot read property 'addEventListener' of undefined,什么意思不认识addEventListener这个命令吗?...求解

淡淡烟草味
淡淡烟草味

Antworte allen(1)
世界只因有你

addEventListener只适用于对标签元素的事件监听

Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage