将输入:文件连接到输入:文本,然后输入:按钮选择文件

时间:2018-10-03 14:56:54

标签: javascript html node.js express

我正在使用系统模板。但是,我不知道如何将input:file连接到input:text和input:button。似乎input:file隐藏在此模板中,我必须使用input:text(已禁用)和input:button。这是代码:

<div class="form-group">
     <label>File upload</label>
     <input type="file" name="img[]" class="file-upload-default">
     <div class="input-group col-xs-12">
          <input type="text" class="form-control file-upload-info" disabled="" placeholder="Upload Image">
          <span class="input-group-append">
               <button class="file-upload-browse btn btn-info" type="button">Upload</button>
          </span>
     </div>
</div>

我必须在水星上使用它。我也该如何传递数据?甚至多次上传。抱歉。谢谢。

1 个答案:

答案 0 :(得分:0)

尝试

<html lang="en">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<head>
<body>
<div class="form-group form-file" >
     <label>File upload</label>
     <input type="file" name="img[]" class="file-upload-default" id="file-1" style="display:none" onchange="checkFile(this)">
     <div class="input-group col-xs-12">
          <input type="text" class="form-control file-upload-info" disabled="" placeholder="Upload Image">
          <span class="input-group-append">
               <button class="file-upload-browse btn btn-info" type="button" onclick="$('#file-1').click()">Upload</button>
          </span>
     </div>
</div>


</body>
<script type="text/javascript">
    var count_file=1;

    function checkFile(dom){
        if($(dom)[0].files[0]){
            console.log($(dom).parent().find('.file-upload-info'));
            var d=$(dom).parent().find('.file-upload-info')[0];
                d.value=($(dom)[0].files[0].name);
        }

    }



</script>
    


</script>