使用document.write编写href时,prettyphoto不会加载

时间:2012-01-25 20:51:53

标签: javascript jquery prettyphoto

我有一些像这样的代码

<span id="$RsC" class="menu" title="Action menu" onclick="menu(\''.$RsC.'\')">click</span>

function menu(id){ 
var d = document.getElementById(id); 
d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170"  rel="prettyPhoto[iframe]" >Doesnt work</a>';
}

<script type="text/javascript" charset="utf-8">
jQuery.noConflict();
jQuery(document).ready(function($) {
$(".pp_pic_holder").remove();
 $(".pp_overlay").remove();
 $(".ppt").remove();
$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'});
});
</script>

问题是,点击“点击”并编写html链接后,prettyPhoto插件无法加载

任何帮助将不胜感激。

EDIT ------------------- 该死的你是冲突再次jquery冲突,但为了让它工作我改变功能:

<script type="text/javascript" charset="utf-8">
jQuery.noConflict();
jQuery(document).ready(function($) {
$(".pp_pic_holder").remove();
 $(".pp_overlay").remove();
 $(".ppt").remove();
$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'});
});
</script>

function menu(id){ 
var d = document.getElementById(id); 
d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170"  rel="prettyPhoto[iframe]" >Doesnt work</a>';
jQuery.noConflict();
jQuery(document).ready(function($) {
$(".pp_pic_holder").remove();
 $(".pp_overlay").remove();
 $(".ppt").remove();
$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'});
});
}

2 个答案:

答案 0 :(得分:1)

它不会以这种方式工作。在页面加载后,您可以为页面上的现有元素初始化prettyPhoto。当你插入一个新元素时,prettyPhoto插件对它一无所知,因为它已经附加了&#34;本身就存在于以前的元素中。您必须在页面上的所有更改后初始化prettyPhoto,或在更改更新的元素后附加它。喜欢这个

function menu(id){ 
var d = document.getElementById(id); 
d.innerHTML ='<a href="somthing;iframe=true&amp;width=400&amp;height=170"  rel="prettyPhoto[iframe]" >Doesnt work</a>';
$('a', d).prettyPhoto({theme:'h0mayun'});
}

ps:我用prettyPhoto的例子做了一个简单的测试,它正在运行

function menu(id){ 
var d = document.getElementById(id); 
d.innerHTML ='<a href="images/fullscreen/3.jpg" rel="prettyPhoto[gallery1]">Test link</a>';
$('a', d).prettyPhoto();
}

答案 1 :(得分:0)

如果您在onClick函数之前执行此$(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'});

在编写对象的html之后,您必须再次执行此操作,以便插件再次初始化。

相关问题