0

我有一些这样的代码

<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插件后没有加载

任何帮助将不胜感激。

编辑-------该死的你冲突它又是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'});
});
}
4

2 回答 2

1

它不会以这种方式工作。加载页面后,您为页面上的现有元素初始化 prettyPhoto。当您插入一个新元素时,prettyPhoto 插件对此一无所知,因为它已经将自己“附加”到之前存在的元素上。您必须在页面上的所有更改后初始化 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();
}
于 2012-01-25T20:58:21.210 回答
0

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

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

于 2012-01-25T20:57:25.823 回答