Javascript jquery查找下一个类
在foreach循环中,我有几个html块,如下所示:Javascript jquery查找下一个类,javascript,jquery,next,Javascript,Jquery,Next,在foreach循环中,我有几个html块,如下所示: <label class="">Replace image/poster:</label> <input type="file" name="replaced_main_image" class="form-control-file-border input-image-preview" />
<label class="">Replace image/poster:</label>
<input type="file" name="replaced_main_image" class="form-control-file-border input-image-preview" />
<!-- preview replaced main image -->
<br />
<label class="">Preview replaced image/poster:</label><br />
<img class="image-preview" width="100" src="#" /> <!-- preview image -->
这很好,但是在本例中,每个类为img preview
的img都会获得源代码。我只想要下一个带有classimg preview
的img
据我所知,我必须更改函数中的一行,看起来应该像:
reader.onload = function(e) {
find next --> $('.image-preview').attr('src', e.target.result);
}
我不知道这个的正确语法是什么…这里:
$(input).nextAll('.image-preview').eq( 0 ).attr('src', e.target.result);
使用input
作为传递到函数中的源代码,然后查找所有下一个.image preview
,并使用.eq(0)
将其限制为第一个:
$(input).nextAll('.image-preview').eq( 0 ).attr('src', e.target.result);
使用input
作为传递到函数中的源代码,然后查找所有下一个。图像预览
,并使用将其限制为第一个。eq(0)
$('.图像预览:eq(2)
根本不显示任何预览$('.图像预览:eq(2)
根本不显示任何预览