本文介绍了使用document.write编写href时,不会加载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>

问题是点击"click" 并编写html链接prettyPhoto插件后无法加载

the problem is that after clicking on "click" and writing html link prettyPhoto plugin doesn't load

任何帮助将不胜感激.

EDIT -------------------该死的冲突再次是jquery冲突,但要使其正常工作,我将功能更改为此:

EDIT-------------------damn you conflict it was again jquery conflict but to got it work i change function to this:

<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'});
});
}

推荐答案

并且它不会以这种方式工作.页面加载后,可以为页面上的现有元素初始化prettyPhoto.当您插入一个新元素时,prettyPhoto插件对此一无所知,因为它已经将自己附加"到了以前存在的元素上.您必须在页面上的所有更改之后初始化prettyPhoto,或者在更改到更新后的元素之后将其附加.像这样

And it is not going to work this way. You initialize prettyPhoto for existing elements on the page after your page was loaded. When you insert a new element, prettyPhoto plugin knows nothing about it, because it already "attached" itself to the elements existed before. You have to initialize prettyPhoto after all changes on the page or attach it after changes to the updated elements. Like this

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的示例进行了简单测试,并且可以正常工作

ps: I've made a simple test with the example of prettyPhoto and it is working

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();
}

这篇关于使用document.write编写href时,不会加载prettyphoto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:30