【问题标题】:Select an element from element's siblings从元素的兄弟姐妹中选择一个元素
【发布时间】:2013-12-13 08:26:20
【问题描述】:

我有 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','');
});

【问题讨论】:

    标签: javascript jquery html css upload


    【解决方案1】:
    $("input[type=file]").on('change',function(){
        $(this).parents('.fileinput-wrapper').find('.fileinput-preview').css('background','none');
    });
    

    【讨论】:

      【解决方案2】:

      试试这个

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

      【讨论】:

        猜你喜欢
        • 2017-08-22
        • 1970-01-01
        • 2019-03-27
        • 1970-01-01
        • 2011-01-09
        • 2022-01-24
        • 1970-01-01
        • 2015-03-22
        • 2021-08-04
        相关资源
        最近更新 更多