2013-11-27 163 views
0

我有4个输入表单元素,我想选择其值改为(准备上传),但输入的兄弟姐妹的元素的元素我的语法不工作:选择从元素的兄弟姐妹

HTML

<div style="overflow:hidden; position: relative; display: inline-block;" class="fileinput-wrapper"> 
    <div style="background:url(http://localhost/project/assets/images/ajax-loader.gif) no-repeat center center" data-provides="fileinput" class="fileinput fileinput-new"> 
     <div style="width: 200px; height: 130px;background:url(http://localhost/project/assets/images/upload_a_photo.png) no-repeat center center" data-trigger="fileinput" class="fileinput-preview thumbnail"> 
     </div> 
    </div> 
    <input type="file" name="photos[]" tabindex="-1" style="opacity: 0; position: absolute; z-index: -1; left: -367.5px; top: 80.9333px;"> 
</div> 

JS

$("input[type=file]").on('change',function(){ 
    $(this).siblings('.fileinput-preview').css('background',''); 
}); 

回答

2
$("input[type=file]").on('change',function(){ 
    $(this).parents('.fileinput-wrapper').find('.fileinput-preview').css('background','none'); 
}); 
+0

谢谢,你的是对的。 – Ramin

+0

太好了。请接受答案。 –

0

试试这个

$(this).next('.fileinput-preview').css('background','none');