老师,问下AMap里事件触发问题
来源:5-1 添加标记-多点标记
学习plus
2020-10-19 14:13:56
# 具体遇到的问题
没哪里写错啊,为什么一个可以运行,一个没反应
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
红色框内无反应,绿色可以运行
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
在这里输入代码,可通过选择【代码语言】突出显示
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=b8be011c2c2cb53ab3503877757970fc"></script>
<style type="text/css">
* {margin: 0; padding: 0; list-style: none;}
#container {width:100%; height: 100%; position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
#setCenterNode,#setZoomNode{
width: 280px;
position: absolute;
z-index: 99;
right: 20px;
top: 50px;
border: 1px solid black;
box-shadow: 0 0 5px black;
background: white;
}
#setCenterNode{
top: 50px;
}
#node li {cursor: pointer;}
#searchNode {width: 280px; height: 30px; background: white; position: absolute; top: 20px; right: 20px;}
</style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
var map = new AMap.Map('container',{
zoom:10,
center:[120,30]
});
map.onclick = function(e){
console.log(e)
}
map.on('click',function(e){
console.log(e)
})
</script>
</body>
</html>
1回答
同学你好,高德地图中有三种绑定事件的方式,里面不包括onclick这种形式,所以点击没有效果。参考文档:
https://lbs.amap.com/api/javascript-api/guide/events/dom_trigger


祝学习愉快!
相似问题