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

发布于 2024-12-29 03:58:04 字数 1491 浏览 2 评论 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>

问题是在点击“click”并编写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'});
});
}

i have some codes like this

<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&width=400&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>

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

any help will be appreciated.

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&width=400&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'});
});
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2025-01-05 03:58:04

但这种方式是行不通的。加载页面后,您可以为页面上的现有元素初始化 PrettyPhoto。当您插入一个新元素时,prettyPhoto 插件对此一无所知,因为它已经将自己“附加”到之前存在的元素上。您必须在页面上发生所有更改后初始化 PrettyPhoto 或在更改更新的元素后附加它。像这样

function menu(id){ 
var d = document.getElementById(id); 
d.innerHTML ='<a href="somthing;iframe=true&width=400&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();
}

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&width=400&height=170"  rel="prettyPhoto[iframe]" >Doesnt work</a>';
$('a', d).prettyPhoto({theme:'h0mayun'});
}

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();
}
琉璃梦幻 2025-01-05 03:58:04

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

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

If you're doing this $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'h0mayun'}); before the onClick function.

You would have to do it again after you have written the html of the object so the plugin would initialize again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文