pass an object through jquery trigger
I'm trying to do something rather simple but I'm getting a strange result. I have an event trigger that I'm using to pass a json object but when it gets through to the other side it's a function... I alert the result and it shows this:
example of alert sting:
alert('value of lattitude? ' + map.curre开发者_如何学PythonntLatLng.lat);
result:
value of lattitude? function () {return this[a];}
I've tried setting up the trigger both with and without the array literal wrapper:
$('body').trigger('updateLocation', [{lat:38.905003, lng:-77.066497}]);
$('body').trigger('updateLocation', {lat:38.905003, lng:-77.066497});
What am I doing wrong?
Try this:
$('body').bind('updateLocation',function(event,obj){
alert(obj.lng);
});
$('body').trigger('updateLocation', [{lat:38.905003,lng:-77.066497}]);
精彩评论