简体   繁体   English

无法使用jQuery将链接元素附加到iframe

[英]Can't append a link element to an iframe with jQuery

I'm building a web app to make my business more automated with HTML/CSS/jQuery in the front end and python in the backend . 我正在构建一个Web应用程序,以使前端HTML / CSS / jQuery和后端python更加自动化。

I wrote an easy script with jQuery that call a route with ajax and recieve the data as json and after that parse it and return a list of iframes depending on it's length : If we have 20 items in that list and we want 5 items per page, create 4 pages and put 5 iframes in each link . 我用jQuery写了一个简单的脚本,该脚本用ajax调用路由并将数据作为json接收,然后解析它并根据其长度返回一个iframe列表:如果该列表中有20个项目,并且每页需要5个项目,创建4页,并在每个链接中放置5个iframe。

Here's the code responsible for this feature : 这是负责此功能的代码:

        $('.pageContent').empty()
                        for (var i = 0; i < vidPageList.length; i++){
                            var videoUrl = vidPageList[i].videoLink
                            var postUrl = vidPageList[i].postLink
                            console.log(postUrl)
                            $('<iframe src ="'+videoUrl+'" class = "videoEntry" width = "360" height = "250"></iframe>').appendTo( ".pageContent" )
                            $('<a class = "postLink" href = "'+postUrl+'"> Video link </a>').appendTo(".videoEntry")
                        }

The problem: 问题:

iframes are added perfectly but the links are not added at all, I don't know why, the console is not showing me any error, I tried to debug the values of postUrl and they are all correct, why is it doing this ? 完美地添加了iframe,但根本没有添加链接,我不知道为什么,控制台没有显示任何错误,我尝试调试postUrl的值,并且它们都是正确的,为什么这样做呢? It looks like the last line responsible for adding the link is not working, I also tried to add everything with one appendTo() call but it only added iframes, what I'm missing here ? 看来负责添加链接的最后一行不起作用,我也尝试通过一个appendTo()调用添加所有内容,但仅添加了iframe,我在这里缺少什么?

The first time your selectors ran, there was no .videoEntry class because it is in the iframe. 首次运行选择器时,没有.videoEntry类,因为它在iframe中。 It may be useful to first make all your html content before appending. 在附加之前先制作所有html内容可能会很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM