【发布时间】:2019-02-18 10:07:59
【问题描述】:
我正在尝试访问传单弹出窗口中的内容。具体来说,我添加了一个带有我想访问的按钮的表单。但现在我只是尝试向弹出窗口本身添加一个事件。
$(".leaflet-popup-content-wrapper .leaflet-popup-content").click(function(e) {
alert("clicked");
});
LeafletJs 弹出标记示例:
<form class="popup-form">
<div class="form-group">
<label class="mb-0" for="comment">Comment:</label>
<textarea class="form-control" rows="4" class="comment">${feature.properties.note}</textarea>
</div>
<div class="d-flex">
<button type="submit" class="btn btn-outline-info btn-sm">Save</button>
<button class="delete-button btn btn-outline-danger btn-sm ml-auto">Delete</button>
</div>
</form>
设置弹出内容的代码
var points = new L.geoJson(null, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.note);
let myPopup = L.DomUtil.create('div', 'content');
content = `
<form class="popup-form">
<div class="form-group">
<label class="mb-0" for="comment">Comment:</label>
<textarea class="form-control" rows="4" class="comment">${feature.properties.id}</textarea>
</div>
<div class="d-flex">
<button type="submit" class="btn btn-outline-info btn-sm">Save</button>
<button class="delete-button btn btn-outline-danger btn-sm ml-auto">Delete</button>
</div>
</form>
`;
layer.bindPopup(content); // Create empty popup
$('#form', myPopup).on('click', function() {
alert("form clicked")
});
受此帖子启发how to catch the click event on a leaflet popup
我不明白这个代码示例的“上下文”是什么?
var content = L.DomUtil.create('div', 'content'),
popup = L.popup().setContent(content);
L.DomEvent.addListener(content, 'click', function(event){
// do stuff
}, context);
【问题讨论】:
-
您到底想访问哪个元素?表单代码是否放置在弹出窗口内?
-
我添加了我正在使用的代码。我的目标是获取删除按钮上的单击事件(删除..)以及保存按钮以向数据库发出更新请求。我正在尝试在更新时手动添加侦听器
标签: jquery html css leaflet popup