开发者

Get attribute on right-click with a jquery plugin

I got a problem here with a jQuery Plugin.

I want to get the attribute "photoId" from the image which the contextmenu has been called on so I can put an option in the menu like 'Delete (photoId)'.

In other words: I right-click on .imgPrev (see html below), I want the attribute photoId to be used in the menu.

Here is the plugin: jQuery ContextMenu Plugin

Code:

$('.imgPrev').contextMenu(menu,{beforeShow: function() { 
        开发者_Python百科            alert($('.imgPrev').attr('photoId'));
                    return true;
                }});

Images are like :

<div class="imgPrev"><img str="..." photoId="541"></div>


old question however below is the solution for anyone else who might have to deal with this issue

You need to replace .imgPrev selector with this.target

$('.imgPrev').contextMenu(menu,{beforeShow: function() { 
                alert($('.imgPrev').attr('photoId'));
                return true;
            }});

with

$('.imgPrev').contextMenu(menu,{beforeShow: function() { 
                alert($('this.target').attr('photoId'));
                return true;
            }});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜