简体   繁体   English

弹出点击事件不起作用

[英]popup click event not working

How to make jquery event after click on the link in the popup (appears after click on the marker). 单击弹出窗口中的链接后如何制作jquery事件(单击标记后出现)。

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8"> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
</head>
<body>
<div id="map" style="width:500px;height:500px;">
<script>
var map = L.map('map').setView([54.6154, 18.8141], 7);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {maxZoom:18}).addTo(map);
L.marker([54.6154,18.8141]).addTo(map).bindPopup("<a href='#' class='A1'>link</a>");
</script>
</div>
<a href='#' class='A1'>link</a>
<script>
$( '.A1' ).click(function() {
alert('halo');
});
</script>
</body>
</html>

The .A1 link in the marker didn't exist when you created the handler. 创建处理程序时,标记中的.A1链接不存在。

You need to use on() to watch for events on .A1 objects that show up later: 您需要使用on()来监视稍后显示的.A1对象上的事件:

$(document).on('click', '.A1', 
  function() {
    alert('halo');
  }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM