Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript prependTo从iframe中最近的指定父div_Javascript_Jquery - Fatal编程技术网

Javascript prependTo从iframe中最近的指定父div

Javascript prependTo从iframe中最近的指定父div,javascript,jquery,Javascript,Jquery,我正在尝试从父对象中的iframe到.prependToa.classdiv使用JQuery 这有多个相同的.class**编辑和编辑iFrame 一切都在同一个域上 因此,从主文档内部: <div class="NewPHOTOS"> **<!--PUT ME HERE!-->** <div class="LinePhoto"> <a href="images/518279f07efd5.gif" target="_bl

我正在尝试从父对象中的
iframe
.prependTo
a
.class
div
使用JQuery

这有多个相同的.class**编辑和编辑iFrame

一切都在同一个域上

因此,从主文档内部:

<div class="NewPHOTOS">
    **<!--PUT ME HERE!-->**
    <div class="LinePhoto">
        <a href="images/518279f07efd5.gif" target="_blank">
            <img src="images/thumb_518279f07efd5.gif" width="50" height="50">
        </a>
    </div>

   <iframe class="uploadLineID_55" width="800px" height="25px" src="../../uploads/uploadiframe.php" scrolling="no" seamless></iframe>
</div>
$(文档)。在(“单击”,“测试”,附录ImageToParent”);
函数appendImagetoParent(){
var div=$('',{'class':'linePhoto'}),
a=$('',{href:'images/TEST.gif',target:''空白'}),
img=$('

使用
frameElement.className
获取包含iFrame的类,并使用该类在父文档中找到正确的iFrame,然后找到最近的
.NewPHOTOS
元素,并预先添加内容,以更jQuery的方式创建。

在页面上有类NewPHOTOS的div中是否有多个iFrame最好在每个iframe的加载事件的父页面中附加一个侦听器,这样您可以针对该帧并训练其父帧(“.NewPHOTOS”)是的。两个都有倍数。如果注释行把所有的元素都加到那个类中,你会期待什么?把第一个,最后一个,中间的一个,其他的都准备好?我假设是iframe@Monty-那太棒了,因为我不是100%确定它会,而且我没有真正的测试方法!
$(document).on("click", '#TEST', function() {

  appendImagetoParent();

});


function appendImagetoParent()  {

var data = '<div class="LinePhoto"><a href="images/TEST.gif" target="_blank"><img src="images/thumb_TEST.gif" width="50" height="50"></a></div>';

$(".NewPHOTOS", window.parent.document).each(function() { $(data).prependTo($(".NewPHOTOS"));
});

/* $(data).prependTo( $(".NewPHOTOS", window.parent.document) ); This prepends to Every .NewPHOTOS */}
 $(parent.document).find('.' + frameElement.className )
                      .closest('.NewPHOTOS')
                      .prepend( data );
$(document).on("click", '#TEST', appendImagetoParent);

function appendImagetoParent()  {

    var div = $('<div />', {'class':'linePhoto'}),
        a   = $('<a />',   {href:'images/TEST.gif', target:'_blank'}),
        img = $('<img />', {src:'images/thumb_TEST.gif', width:'50', height:'50'});

    $(parent.document).find('.' + frameElement.className )
                      .closest('.NewPHOTOS')
                      .prepend( div.append( a.append(img) ) );
}