通过jquery触发器传递对象 [英] pass an object through jquery trigger

查看:131
本文介绍了通过jquery触发器传递对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一些比较简单的事情,但我得到了一个奇怪的结果。我有一个事件触发器,我用来传递一个json对象,但当它通过对方它是一个功能...我提醒结果,它显示:



alert sting的例子:

  alert('values of lattitude?'+ map.currentLatLng.lat); 

结果:


格值的值function(){return this [a];}


我已经尝试使用和不使用数组文字包装器来设置触发器:$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ );
$('body')。trigger('updateLocation',{lat:38.905003,lng:-77.066497});

我做错了什么?

解决方案

尝试这样:

  $('body')bind('updateLocation' function(event,obj){
alert(obj.lng);
});

$('body')。trigger('updateLocation',[{lat:38.905003,lng:-77.066497}]);


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.currentLatLng.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}]);

这篇关于通过jquery触发器传递对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆