Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
使用jQuery选择当前div的第一个图像_Jquery_Image - Fatal编程技术网

使用jQuery选择当前div的第一个图像

使用jQuery选择当前div的第一个图像,jquery,image,Jquery,Image,我只是发布了一个类似的问题,关于这一点,以发现它并不完全是我所需要的。我道歉 这是我正在使用的代码: jQuery(document).ready(function($) { $('.upload_button').click(function() { targetfield = $(this).prev('.logo_url'); tb_show('', 'media-upload.php?type=image&TB_iframe=true');

我只是发布了一个类似的问题,关于这一点,以发现它并不完全是我所需要的。我道歉

这是我正在使用的代码:

jQuery(document).ready(function($) { 

  $('.upload_button').click(function() {

    targetfield = $(this).prev('.logo_url');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');

    window.send_to_editor = function(html) {
      imgurl = $('img',html).attr('src');
      jQuery(targetfield).val(imgurl);
      tb_remove();

      $('.upload_preview img').attr('src',imgurl); // THIS IS WHERE I'M HAVING PROBLEMS

      $('#submit_options_form').trigger('click');
    };

    return false;

  });
});
我不是jQuery的高手,对一些事情还是新手。我需要在preview类中填充img标记的url,但只能在获取url的类上填充。我现在拥有的将填充每个具有该类的图像标记。非常感谢您的帮助

我需要它像填充输入字段一样填充它

编辑

下面是一些HTML示例。我在一个页面上使用这些的倍数

<li class="slide">

            <input class="logo_url" name="theme_wptuts_options[logo]" value="src[]" />
                <input class="upload_button" type="button" class="button" value="<?php _e( 'Upload Logo' ); ?>" />

                <div class="upload_preview" style="min-height: 100px;">
                    <img style="max-width:100%;" src="src[]" />
                </div>

            <button class="remove_slide button-secondary">Remove This Slide</button>

</li>
:第一个选择器执行以下操作:

$('.upload_preview:first img').attr('src', imgurl); 
:第一个选择器执行以下操作:

$('.upload_preview:first img').attr('src', imgurl); 
imgurl*编辑于美国东部时间2012年5月11日晚上9:47*

可能就是这个!我无法在小提琴中测试,因为我无法在小提琴中执行window.send功能

JQuery

imgurl*编辑于美国东部时间2012年5月11日晚上9:47*

可能就是这个!我无法在小提琴中测试,因为我无法在小提琴中执行window.send功能

JQuery


用法:eq0,它将拾取第一个元素,这是与之相比的最佳方式。第一个。最后一个等:

$('.upload_preview img:eq(0)').attr('src',imgurl);

用法:eq0,它将拾取第一个元素,这是与之相比的最佳方式。第一个。最后一个等:

$('.upload_preview img:eq(0)').attr('src',imgurl);

经过大量的尝试和错误,这就是我最终得到的,我想要的效果。我感谢大家的帮助和回答

jQuery(document).ready(function($) { 
$('.upload_button').click(function() {
     targetfield = $(this).prev('.logo_url');
     imgpreview = $(this).parent().find('img');
     tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
window.send_to_editor = function(html) {
     imgurl = $('img',html).attr('src');
     jQuery(targetfield).val(imgurl);
     tb_remove();
     $(imgpreview).attr('src', imgurl);
     $('#submit_options_form').trigger('click');
};
return false;
});
});

经过大量的尝试和错误,这就是我最终得到的,我想要的效果。我感谢大家的帮助和回答

jQuery(document).ready(function($) { 
$('.upload_button').click(function() {
     targetfield = $(this).prev('.logo_url');
     imgpreview = $(this).parent().find('img');
     tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
window.send_to_editor = function(html) {
     imgurl = $('img',html).attr('src');
     jQuery(targetfield).val(imgurl);
     tb_remove();
     $(imgpreview).attr('src', imgurl);
     $('#submit_options_form').trigger('click');
};
return false;
});
});

这不起作用:不管发生什么,它都会填充img标记的第一个实例。对不起,这不是你想要的?这不起作用:不管发生什么,它都会填充img标记的第一个实例。对不起,这不是你想要的?我尝试使用它时运气不佳,我相信是因为它在另一个函数中,对吗?所以我用“.upload_button”来代替“this”,但它会填充每个img字段,而不仅仅是一个:为什么不在window.sendtoeditor函数下面拉这行代码呢?但请将其保存在$'中。上载按钮。单击函数?我没有看到任何if语句,所以应该是好的。它需要在window.sender中,因为变量imgurl是填充img字段的。好的,知道了…是一个全局变量,如'var whichLi;'如上所述…在窗口之前。发送设置该变量,然后通过$whichLi处理程序调用它。感谢您的帮助!然而,我补充了答案,我终于找到了答案。我创建了一个变量,该变量取类的父类,然后找到img标记,这样我就可以使用这两个变量来实现预览图像。再次感谢你尝试帮助我,我很感激。我尝试使用它时没有运气,我相信是因为它在另一个函数中,对吗?所以我用“.upload_button”来代替“this”,但它会填充每个img字段,而不仅仅是一个:为什么不在window.sendtoeditor函数下面拉这行代码呢?但请将其保存在$'中。上载按钮。单击函数?我没有看到任何if语句,所以应该是好的。它需要在window.sender中,因为变量imgurl是填充img字段的。好的,知道了…是一个全局变量,如'var whichLi;'如上所述…在窗口之前。发送设置该变量,然后通过$whichLi处理程序调用它。感谢您的帮助!然而,我补充了答案,我终于找到了答案。我创建了一个变量,该变量取类的父类,然后找到img标记,这样我就可以使用这两个变量来实现预览图像。再次感谢您的帮助,我很感激。这么简单的解决方案……可惜找到它并不容易!好工人!这么简单的解决方案…可惜发现它很少容易!好工人!