简体   繁体   English

Chrome 中的 HTML input type="file" 不显示文本框

[英]HTML input type="file" in Chrome does not show textbox

I have problem with <input type="file" /> in Chrome - it does not show the textbox near the 'browse' button.我在 Chrome 中遇到<input type="file" />问题 - 它没有显示“浏览”按钮附近的文本框。 What is a best way to show a standard file input (textbox+button) in Chrome?在 Chrome 中显示标准文件输入(文本框+按钮)的最佳方式是什么?

This is the default behavior of Google chrome as well as Safari.这是 Google chrome 和 Safari 的默认行为。 Read this blog for a solution阅读博客以获取解决方案

The box is there, although it is not designed.盒子在那里,虽然它不是设计的。 It might be on the "wrong" side of the window, but it's there.它可能在窗口的“错误”一侧,但它就在那里。

Just for the matter - put a border around it - and you'll see it's there.只是为了这个问题 - 在它周围放置一个边框 - 你会看到它在那里。

  <input type="file" style="border: solid 1px red">

Also, after you select a file - you get the name of it.此外,在您选择一个文件后 - 您会得到它的名称。

<input type="file"/> has different visual appearance depending on the browser. <input type="file"/>根据浏览器的不同具有不同的视觉外观。 On some browsers it is a text field with a button in others its just a button.在某些浏览器上,它是一个带有按钮的文本字段,而在其他浏览器中它只是一个按钮。 Since the element isn't very styleable there isn't much you can do about it.由于该元素不是很有风格,因此您无能为力。

If you really want a file upload to look/behave different from the default implementation flash is the way to go.如果您真的希望文件上传的外观/行为与默认实现不同,那么 Flash 就是您要走的路。

For example many sites use sfwUpload .例如,许多站点使用sfwUpload For full styleing freedom, you can make it invisible and place it on top of a html button via positioning.为了获得完全的样式自由,您可以使其不可见并通过定位将其放置在 html 按钮的顶部。

Another way to work with the file upload inputs are to make them invisible via visibility: hidden , position them on top of other elements and thus forgo the use of flash, but the implementations are rarely very nice, so i wouldn't recommend it.处理文件上传输入的另一种方法是通过visibility: hidden使它们不visibility: hidden ,将它们放置在其他元素的顶部,从而放弃使用flash,但实现很少非常好,所以我不会推荐它。

You could override the default behaviour and swap the control appearence alltogether.您可以覆盖默认行为并一起交换控件外观。 Found this today researching how to edit the css on fileupload.今天发现这个研究如何编辑文件上传的css。

The file input element is styled differently depending on your browser (and probably OS - I've only ever used Windows).文件输入元素的样式取决于您的浏览器(可能还有操作系统 - 我只使用过 Windows)。 If you look at the same page with a file input element in FF, IE and Chrome, it will appear differently in each browser.如果在 FF、IE 和 Chrome 中查看带有文件输入元素的同一个页面,它在每个浏览器中的显示都会不同。

Why do you need to display the textbox anyway?为什么你需要显示文本框呢? In FF and IE you can't type directly into it anyway, so the only usage would be to display the filepath of the selected file;在 FF 和 IE 中,无论如何你都不能直接输入,所以唯一的用法是显示所选文件的文件路径; which Chrome already does for you, just not in a box. Chrome 已经为你做了,只是不在一个盒子里。

I found a link from someone else who was having this problem, solution here .我从遇到此问题的其他人那里找到了一个链接,解决方案在这里

It doesn't specifically mention chrome, but safari does the same thing apparently.它没有特别提到 chrome,但 safari 显然做了同样的事情。 (The link was an accepted answer posted in a chrome discussion) (该链接是在 chrome 讨论中发布的已接受答案)

edit: wow, second time this morning that I've been out googled by another member!编辑:哇,今天早上我第二次被另一个成员用谷歌搜索了! at least questions are getting answered!至少问题得到了回答!

Sometimes it is just caused by a javascript code similar to this one:有时它只是由类似于此的 javascript 代码引起的:

function someOnClickHandler(e)
{
    e.preventDefault();  // it kills the file dialog
}

// somewhere:
$('.some-selector-which-contains-the-file-elem').on('click', someOnClickHandler); 

Most of the times type file got display:none style.大多数时候类型file都有display:none样式。 In that case use !important to display the input field.在这种情况下,使用!important来显示输入字段。

<input id="cv_file" type="file" name="cv" style="display:block !important;"/>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM