leaflet - L.marker.bindPopup() 的 onpopupload 事件?
问题描述
假设我有一些这样的代码:
L.marker({lat: 30.266293, lon: -97.656965}, {icon: myIcon})
.addTo(mymap)
.bindPopup("<a href='#' class='test'>click me!</a>");
我希望能够$('test').click(function() { ... });
在弹出窗口加载后做。
我该怎么做?我可以使用某种 onpopupload 事件吗?
解决方案
是的,图层上有一个事件popupopen
var marker = L.marker({lat: 30.266293, lon: -97.656965}, {icon: myIcon})
.addTo(mymap)
.bindPopup("<a href='#' class='test'>click me!</a>");
marker.on('popupopen',(e)=>{
$('.test').click(function() { ... });
});
PS:点击事件会添加到test
元素中,必须在前面加一个点test
,否则找不到元素--> $('.test')
推荐阅读
- c++ - stl 函数和函数类型 vs 函数指针类型
- amazon-web-services - 在 AWS SAM 模板中创建 RDS 完全访问角色
- javascript - 页面加载上的活动类未触发
- haskell - Haskell 避免在返回可能的函数中使用双重包装的可能
- c# - 如何在不按住鼠标左键的情况下用鼠标拖动任何对象?
- javascript - JavaScript - 复选框循环未正确汇总价格
- doctrine - Symfony4:当 OneToMany 和 OneToOne 在同一实体上时删除问题
- azure-pipelines - 托管代理 devops 需要很长时间或取消
- codeigniter - Codeigniter 3 应用程序错误:如果标题中有变音符号,将标题转换为 slug 不起作用
- database - 记录中的所有字段都没有映射到 apache-nifi 列