How can I make a map-marker's popupContent be a random phrase?

المشرف العام

Administrator
طاقم الإدارة
I'm using leaflet.js to make a map and I need help with the javascript required to make a map-marker generate a random phrase with each click.

I've used this code to generate random text:

function randomText() {var items = new Array( "Ow", "Stop poking me", "Stop", "Leave me alone", "Don't you have anything better to do?", "You're hurting me", "Go away");var i = Math.floor(Math.random() * items.length);return items;}But when I try to put it in popup content it's blank.

I tried

.bindPopup(document.write(randomText()));My current gist has .bindPopup(randomText()); because it is, at least, not blank and generates a random phrase with each page load.

Here is my gist https://gist.github.com/joshuahouston/800cd59aab26c264f3bc

And the working map with where I'm currently stuck http://bl.ocks.org/joshuahouston/800cd59aab26c264f3bc



أكثر...
 
أعلى