how to get a button in an Openlayers popup?
I am trying to put a button inside of an Openlayers popup. While the button appears to display correctly with the following code, the开发者_运维问答 function 'handlerFunc' does not execute when the button is clicked. The segment of code I have posted is all within another function (so handlerFunc is actually a nested function). I'm using JQuery for the button itself. Any ideas on what might be going wrong? Thanks!
var feature = new OpenLayers.Feature(presences, ll);
feature.popupClass = popupClass;
feature.data.popupContentHTML = "<button id='popupButton'>Click me</button>";
feature.data.overflow = (overflow) ? "auto" : "hidden";
feature.data.icon = markerIcon;
$('#popupButton').button();
$('#popupButton').click(handlerFunc);
function handlerFunc() {
// do something
}
Most likely reason is that your button doesn't exist when you bind to a click
event. $('#popupButton')
returns null
. Instead of using $('#popupButton').click(handlerFunc);
try $('#popupButton').live('click', handlerFunc);
. That means that we bind to an event not only when DOM is built, but when object appears.
精彩评论