优化代码使得点击name值为“图书馆时”会在div为picshow中加载照片pic <div id="picshow"> </div> var marker = L.marker(point.latlng).addTo(map); marker.bindPopup(point.name); marker.on('click', function() { if (point.name === '图书馆') { document.querySelector("#section3 input").value = "您点击了图书馆"; document.querySelector("#section3 input").style.fontSize = "20px"; }else if (point.name === "敬亭学堂"){ document.querySelector("#section3 input").value = "您点击了敬亭学堂"; document.querySelector("#section3 input").style.fontSize = "20px"; }else if (point.name === "新安学堂"){ document.querySelector("#section3 input").value = "您点击了新安学堂"; document.querySelector("#section3 input").style.fontSize = "20px"; } })
时间: 2024-01-11 12:02:43 浏览: 36
可以通过修改marker.on的回调函数中的代码来实现点击name值为“图书馆时”在div为picshow中加载照片pic:
```
var marker = L.marker(point.latlng).addTo(map);
marker.bindPopup(point.name);
marker.on('click', function() {
if (point.name === '图书馆') {
document.querySelector("#section3 input").value = "您点击了图书馆";
document.querySelector("#section3 input").style.fontSize = "20px";
document.querySelector("#picshow").innerHTML = "<img src='pic.jpg'>";
} else if (point.name === "敬亭学堂") {
document.querySelector("#section3 input").value = "您点击了敬亭学堂";
document.querySelector("#section3 input").style.fontSize = "20px";
document.querySelector("#picshow").innerHTML = "";
} else if (point.name === "新安学堂") {
document.querySelector("#section3 input").value = "您点击了新安学堂";
document.querySelector("#section3 input").style.fontSize = "20px";
document.querySelector("#picshow").innerHTML = "";
}
})
```
其中,当点击的是“图书馆”时,将picshow的innerHTML设置为包含图片的HTML代码,图片的路径为'pic.jpg';当点击的是“敬亭学堂”或“新安学堂”时,picshow的innerHTML清空。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)