希望 永远是快乐的.

有一种沉默叫霸气,有一种内敛叫个性,有一种简单叫深遂,有一种不屑叫自我。

导航

Jquery绑定img的click事件

用JQUERY给IMG element绑定click事件的时候,直接用img.click(function(){...})不起作用,如下面代码
$("img.ms-rteImage-LightBox").click(function(){        
    SP.UI.ModalDialog.showModalDialog({
        url: $(this).attr("src"),
        title: $(this).attr("alt")
    });
});

解决这个问题需要用jquery里面bind函数去附加click event. 如下:

$("img.ms-rteImage-LightBox").bind("click",function(){        
    SP.UI.ModalDialog.showModalDialog({
        url: $(this).attr("src"),
        title: $(this).attr("alt")
    });
});

posted on 2011-08-12 11:10  希望(Jack)  阅读(6539)  评论(0编辑  收藏  举报