简体   繁体   English

使用Jquery将iframe插入类

[英]Insert Iframe to a class using Jquery

The below script inserts an iframe to the class rightImage. 下面的脚本将一个iframe插入到rightImage类中。 The problem is there are multiple elements that use the rightImage class so the iframe is showing multiple times. 问题在于,有多个元素使用rightImage类,因此iframe会显示多次。 How do I get it so it only add's it the last element that uses the rightImage class so therefore the iframe only appears once? 如何获得它,使其仅添加使用rightImage类的最后一个元素,因此iframe仅出现一次?

 $(document).ready(function() {
  $(".rightImage").append("<iframe src='test.uk'></iframe>");  
   });

I have no control over the parent page so that's why I have to do it this way. 我无法控制父页面,所以这就是为什么我必须这样做。

$(".rightImage:last").append("<iframe src='test.uk'></iframe>");

or 要么

$(".rightImage").last().append("<iframe src='test.uk'></iframe>");

or 要么

$(".rightImage").eq(-1).append("<iframe src='test.uk'></iframe>");

You can use :last selector: 您可以使用:last选择器:

Selects the last matched element. 选择最后一个匹配的元素。

$(".rightImage:last").append("<iframe src='test.uk'></iframe>");

or .last() : .last()

Reduce the set of matched elements to the final one in the set. 将匹配元素的集合减少到集合中的最后一个。

$(".rightImage").last().append("<iframe src='test.uk'></iframe>");

Try .last() or :last 尝试.last():last

Reduce the set of matched elements to the final one in the set. 将匹配元素的集合减少到集合中的最后一个。

$(".rightImage").last().append("<iframe src='test.uk'></iframe>");

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

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