Ghost精选图片和iframe问题(Ghost featured image and iframe issue)

编程入门 行业动态 更新时间:2024-10-26 17:20:43
Ghost精选图片和iframe问题(Ghost featured image and iframe issue)

HTML

<div class="blog-post"> <div class="blog-image"> <a href="#"><img src="img/featured-img.jpg"/></a> </div> <div class="blog-details"> <h3>Post Title Here</h3> <ul class="blog-meta"> <li>Date</li> <li>Author</li> </ul> <div class="blog-excerpt"> <iframe width="560" height="315" src="https://www.youtube.com/embed/yH4zLmi_6n0" frameborder="0" allowfullscreen></iframe> </div> </div>

我用了以下的js

function iframe_posts() { var video_url = $(".blog-details").find("iframe").attr("src"); $(".blog-image").html('<iframe width="560" height="315" src="' + video_url + '" frameborder="0" allowfullscreen></iframe>'); } } iframe_posts();

通过此代码替换为iframe,但在每个“博客帖子”中显示相同的iframe。 我想只为每个“博客帖子”显示父视频。 假设我有2个博客帖子和2个不同的iframe。 现在我想显示iframe 是

任何人都可以帮助我。

HTML

<div class="blog-post"> <div class="blog-image"> <a href="#"><img src="img/featured-img.jpg"/></a> </div> <div class="blog-details"> <h3>Post Title Here</h3> <ul class="blog-meta"> <li>Date</li> <li>Author</li> </ul> <div class="blog-excerpt"> <iframe width="560" height="315" src="https://www.youtube.com/embed/yH4zLmi_6n0" frameborder="0" allowfullscreen></iframe> </div> </div>

and i used the following js

function iframe_posts() { var video_url = $(".blog-details").find("iframe").attr("src"); $(".blog-image").html('<iframe width="560" height="315" src="' + video_url + '" frameborder="0" allowfullscreen></iframe>'); } } iframe_posts();

By this code Image replacing with iframe but same iframe showing in every "blog-post". I want to show the parent video only for each "blog-post". Suppose i have 2 blog-post with 2 different iframe. Now i want to show the iframe in are

Anyone can help me please.

最满意答案

您必须通过循环重复元素来处理各个实例

可以做多种方式,但我会从顶级重复容器开始... class=blog-post

$('.blog-post').each(function(){ // `this` is current instance of `blog-post` var $post = $(this); // use `find()` to look inside this `$post` instance var video_url = $post.find('iframe').attr('src'); $post.find('.blog-image').html('....'); });

You have to deal with individual instances by looping over repeating elements

Can do this numerous ways but I would start at the top level repeating containers ... class=blog-post

$('.blog-post').each(function(){ // `this` is current instance of `blog-post` var $post = $(this); // use `find()` to look inside this `$post` instance var video_url = $post.find('iframe').attr('src'); $post.find('.blog-image').html('....'); });

更多推荐

iframe,src,class,电脑培训,计算机培训,IT培训"/> <meta name="description&

本文发布于:2023-07-09 00:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082136.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   iframe   Ghost   issue   image

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!