开发者

script don't work on FF

Plugin's code is(i use this script - http://www.tanabi.com/js/jquery.imagemap.js):

if(typeof ev.originalTarget.actualPosX == 'undefined'){
     jQuery.imagemap.ffGetPosition(ev.originalTarget);
}

i have an error on Firefox - ev.originalTarget is undefined, at 86 line

and my code:

jQuery.fn.imagecoords = function() {
    return this.each(function(){
        jQuery(this).click(function(ev){
                        //var coords;
            var x = jQuery.imagemap.getEventX(ev);
            var y = jQuery.imagemap.getEventY(ev);
                       开发者_运维技巧 jQuery('#x').val(x+4);
                        jQuery('#y').val(y+2);
                        jQuery('#new_point').remove();
                        jQuery('#map').append('<a href="javascript:void(0)" id="new_point" class="bullet" rel="' + x + '-' + y + '" style="left: ' + x + 'px; top: ' + y + 'px; display: block; ">&nbsp;</a>');
                        return 0;
        });
    });
};


You can use the event.target of jQuery. http://api.jquery.com/category/events/event-object/#event.target


Your problem is that what jQuery is handing you is NOT the actual event object but some jQuery wrapper object around the real thing. You probably want ev.originalEvent.originalTarget here.


You need to check if ev.originalTarget is defined before accessing ev.originalTarget.something.

if(ev.originalTarget) { 
    if(typeof ev.originalTarget.actualPosX == 'undefined') {
        jQuery.imagemap.ffGetPosition(ev.originalTarget);
    }
}
else {
    // Handle undefined or null originalTarget
}

You could also use

if (typeof(ev.originalTarget) != 'undefined' && ev.originalTarget != null)

instead of

if(ev.originalTarget)

but if(ev.originalTarget) will be faster.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜