简体   繁体   English

如何显示在输入类型文件中选择了哪个文件?

[英]How to show which file is selected in Input type File?

Using this code below, I edit the style of mine INPUT TYPE FILE button.使用下面的这段代码,我编辑了我的 INPUT TYPE FILE 按钮的样式。 The problem I am getting now is its not showing which file user had selected.我现在遇到的问题是它没有显示用户选择了哪个文件。 I don't know how to do this.. :(我不知道该怎么做.. :(

HTML Code: HTML代码:

<div class="giz-upload">
<input type="file" size="40" name="d4p_attachment[]">
</div>

Style.css样式文件

div.giz-upload{
    width: 157px;
    height: 57px;
    background: url(http://www.gizmoids.com/wp-content/sicons/upload.png);
background-size: 80px 60px;
background-repeat:no-repeat;
overflow: hidden;
}

div.giz-upload input {
    display: block !important;
    width: 157px !important;
    height: 57px !important;
    opacity: 0 !important;
    overflow: hidden !important;
}

Here is JSFIDDLE URL : http://jsfiddle.net/sunita1993/avn9n6sp/这是 JSFIDDLE 网址: http : //jsfiddle.net/sunita1993/avn9n6sp/

Please check the following code, hope it will work :)请检查以下代码,希望它会起作用:)

 $('input[type=file]').change(function (e) { $(this).parents('.giz-upload').find('.element-to-paste-filename').text(e.target.files[0].name); });
 .giz-upload { display: block !important; height: 57px !important; background: url(http://www.gizmoids.com/wp-content/sicons/upload.png); background-size: 80px 60px; background-repeat:no-repeat; padding-left: 90px; } .giz-upload input { display: none; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <label class="giz-upload"> <input type="file" size="40" name="d4p_attachment[]" /> <span class="element-to-paste-filename"></span> </label>

You can do it using javascript.您可以使用 javascript 来完成。 I let you an example using the jQuery framework:我给你一个使用 jQuery 框架的例子:

$(function() {

    $("input").on("change", function() {

        var file = this.files;
        console.log(file);

    });

});

When you select a file the input value will change you can get access to the file, file variable will contain an object with the data from the file and you can get what you need from it and put it on a span element or where you want当您选择一个文件时,输入值将更改您可以访问该文件, file变量将包含一个带有文件中数据的对象,您可以从中获取所需内容并将其放在span元素或您想要的位置

An example on JsFiddle JsFiddle 的一个例子

Because in div.giz-upload input you have set the opacity property to 0.因为在div.giz-upload input您已将opacity属性设置为 0。

Remove opacity and it will show file's name.删除不透明度,它将显示文件名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除未选择的文件,并在输入类型文件中使用jquery成功上传文件名 - how to remove no file selected and place the file name which is uploaded successfully using jquery in input type file 如何显示使用相同 html 输入类型 = 文件选择的视频和图像的预览 - how to show preview of a video and an image selected using the same html input type=file 如何使用获取所选文件的完整路径<Input Type=“file” /> - How to get a full path of a selected file using <Input Type=“file” /> 如何检查输入类型=“文件”是否选择了文件? - How to check an input type=“file” has a file selected? 我们可以为从输入 type="file" 中选择的文件创建一个自定义的 URL,该文件指向文件并在任何使用的地方下载文件? - Can we create a customized URL for the file which is selected from the input type="file" which points to file and downloads the file wherever used? 样式输入 type=&quot;file&quot; - 没有出现“未选择文件” - Styling input type="file" - no "No file selected" appear 更改输入类型文件选择的名称文件 - Change name File selected by input type file 如何将预选的文件显示为angularjs中输入的文件类型? - How to show preselected file to a file type input in angularjs? 显示在文件输入标签中选择的所有图像 - Show all images selected in file input tag 在不发送表单的情况下显示一些输入类型的文本,这些文本等于我的输入文件中所选文件的数量 - show a number of inputs type text equal to the number of selected files in my input file without send form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM