jQuery绑定img的click事件

Jquery绑定img的click事件

用JQUERY给IMGelement绑定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")
});
});

d当然了也可以 <img src="" /> 这样的方式来添加
posted @ 2013-05-24 11:26  M小卢  阅读(2475)  评论(0)    收藏  举报