轉: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

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

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

相关文章
相关标签/搜索