使用 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&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>
问题是在点击“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&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'});
});
}
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
但这种方式是行不通的。加载页面后,您可以为页面上的现有元素初始化 PrettyPhoto。当您插入一个新元素时,prettyPhoto 插件对此一无所知,因为它已经将自己“附加”到之前存在的元素上。您必须在页面上发生所有更改后初始化 PrettyPhoto 或在更改更新的元素后附加它。像这样
ps:我用 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
ps: I've made a simple test with the example of prettyPhoto and it is working
如果您在 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.