Mat*_*iby 1 jquery jquery-plugins prettyphoto
我有这个片段在我的整个网站使用的主js文件上
$("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'light_square',
showTitle: false,
allow_resize: true
});
Run Code Online (Sandbox Code Playgroud)
问题是,在某些页面上,prettyPhoto未定义并导致firebug出错,所以我想我会尝试这个
if(typeof prettyPhoto=="undefined"){
//do nothing
}else{
$("a[rel^='prettyPhoto']").prettyPhoto({
theme: 'light_square',
showTitle: false,
allow_resize: true
});
}
Run Code Online (Sandbox Code Playgroud)
但这总是执行为true,即使在prettyPhoto可用的页面上......任何想法
试试这个:
if (typeof $.fn.prettyPhoto == "function") {
// we have prettyPhone on the page
}
Run Code Online (Sandbox Code Playgroud)