鍍金池/ 問答/網(wǎng)絡(luò)安全  HTML/ 引用高德地圖js的api,給點(diǎn)標(biāo)記添加點(diǎn)擊事件,沒有反應(yīng)

引用高德地圖js的api,給點(diǎn)標(biāo)記添加點(diǎn)擊事件,沒有反應(yīng)

項(xiàng)目中引用高德地圖api,給點(diǎn)標(biāo)記添加點(diǎn)擊事件,沒有反應(yīng)也沒有報(bào)錯(cuò)

創(chuàng)建點(diǎn)標(biāo)記代碼:

var marker = new AMap.Marker({//坐標(biāo)圖
icon: icon,//24px*26px
position: vue.customer[i].position,
title: vue.customer[i].name,
zIndex: 200,
clickable: true,
map: map
});
new AMap.Marker({//坐標(biāo)名
content: "<div class='custom'>" + vue.customer[i].name + "</div>",
position: vue.customer[i].position,
offset: new AMap.Pixel(0, 0),
zIndex: 200,
map: map
});

給點(diǎn)標(biāo)記添加click事件

AMap.event.addListener(marker, 'click', function() {
console.log("1111");
});

運(yùn)行后點(diǎn)擊沒有反應(yīng)也沒有報(bào)錯(cuò),斷點(diǎn)顯示沒有進(jìn)入方法

回答
編輯回答
孤星

方法是對(duì)的,我把點(diǎn)擊事件寫在了外面,所以點(diǎn)擊事件沒有觸發(fā)

2017年3月12日 04:29