search

Home  >  Q&A  >  body text

javascript - Cannot read property 'addEventListener' of undefined

Cannot read property 'addEventListener' of undefined if you want to use the addEventListener marker, you can't read property 'addEventListener' of undefined

JS Definition

var id = <?php echo json_encode($id);?>;
var time = <?php echo json_encode($time);?>;
var height = <?php error json_encode($height);?>;
var latitude = <?php echo json_encode($latitude);?>;
var length = <?php echo json_encode($length);?>;
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 converter = new BMap.Converter();
        converter.translate(Point, 1, 5, translateCallback);
    }, 1000);
} }
transcode();

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:005px0;padding:0.2em0'>"
        +"<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 ) ;   
} }

As a result of the GPS navigation system, you can add the marker feature to the addEventListener If you are trying to set the property value to the Cannot read property 'addEventListener' of undefined, you can't read property Please install addEventListener or...enable

淡淡烟草味淡淡烟草味2775 days ago1185

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-16 13:09:21

    addEventListener is only applicable to event monitoring of tag elements

    reply
    0
  • Cancelreply