百度地圖infoWindow添加點擊事件


1、方法一

創建dom
const img = new Image();
img.src = i.info.img;
img.onclick = function () {
      console.log(999);
}

2、方法二

this.map.openInfoWindow(infoWindow, targetpoint); // 開啟信息窗口
   if (!infoWindow.isOpen()) {
   //如果沒有打開,則監聽打開事件,獲取按鈕,添加事件
      infoWindow.addEventListener("open", function () {
        document.getElementById("test"+i.id).onclick = function (e) {
          that.isVisible = true;
          that.imgSrc = i.info.img;
        }
       })
   } else {
     //如果沒有打開,則監聽打開事件,獲取按鈕,添加事件
      document.getElementById("test"+i.id).onclick = function (e) {
        that.isVisible = true;
        that.imgSrc = i.info.img;
      } 
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM