简体   繁体   中英

can I generate a custom <input type=file>

Is there a way to construct another element that can enable posting of files to server?
without using the tag

<input type='file'>

If you want to do drag-and-drop, you can use the new drag and drop stuff from HTML5 (supported in Firefox and Chrome as of this writing). That doesn't require an input type='file' .

Otherwise, you cannot do this in pure HTML+JavaScript without an input type='file' element. As thejh points out (in a now-deleted answer), you can do this without actually submitting a form by using the File API , but that still requires using an input type='file' (although it doesn't require submitting a form and refreshing the page). Here's an example (here on SO) of reading a file using JavaScript and the File API; from there, sending it via ajax is a trivial step. And this is useful for providing an enhanced user experience on those browsers that support the File API (progress bars, early detection and reporting of unsupported file types, early detection and reporting of files that are too big, etc.).

You can, of course, do this with non-HTML/JavaScript technologies like Flash and (signed) Java applets, but if you're looking for a "pure" plug-in-free mechanism, the good old input type='file' is still your only bet. You can progressively-enhance it via the File API on browsers that support it, though, which is useful.

You can do it by FLASH, but I don't think there is any other way in html.

Why you don't you want to use input ?

Anyway, check out uploadify (nice jQuery plugin), could be helpful: http://www.uploadify.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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