FileUpload系列:(4)HTML5的 input:f
网页上添加一个input file HTML控件:
<inputid="File1"type="file"/>
默认情况下,所有文件类型都会显示出来,如果想限制它只显示特定的文件类型呢,比如“word“,”excel“,”pdf“文件
解决办法是可以给它添加一个accept属性,比如:
<inputid="File1"type="file"accept=".xls,.doc,.txt,.pdf"/>
还有另外一种形式:
<inputtype="file"accept="application/msword"><br><br>accept属性列表<br>
<form><inputtype="file"name="pic"id="pic"accept="p_w_picpath/gif,p_w_picpath/jpeg"/></form>
多个类型用逗号分隔开,因为accept是html5的新特性,所以火狐和IE的支持就显得单薄了
But,这只是最简单的掩人耳目的做法,还是能选择其它文件类型。
所以,如果要做到真正意义上限制类型做法(其实这种算不上限制,只是把你要的文件类型默认显示出来而已,并不是说不能选择其它的),还是要通过js或者后台来控制。
那么accept能限制哪些文件呢?见下表。
*.3gppaudio/3gpp,video/3gpp3GPPAudio/Video*.ac3audio/ac3AC3Audio*.asfallpication/vnd.ms-asfAdvancedStreamingFormat*.auaudio/basicAUAudio*.csstext/cssCascadingStyleSheets*.csvtext/csvCommaSeparatedValues*.docapplication/mswordMSWordDocument*.dotapplication/mswordMSWordTemplate*.dtdapplication/xml-dtdDocumentTypeDefinition*.dwgp_w_picpath/vnd.dwgAutoCADDrawingDatabase*.dxfp_w_picpath/vnd.dxfAutoCADDrawingInterchangeFormat*.gifp_w_picpath/gifGraphicInterchangeFormat*.htmtext/htmlHyperTextMarkupLanguage*.htmltext/htmlHyperTextMarkupLanguage*.jp2p_w_picpath/jp2JPEG-2000*.jpep_w_picpath/jpegJPEG*.jpegp_w_picpath/jpegJPEG*.jpgp_w_picpath/jpegJPEG*.jstext/javascript,application/javascriptJavaScript*.jsonapplication/jsonJavaScriptObjectNotation*.mp2audio/mpeg,video/mpegMPEGAudio/VideoStream,LayerII*.mp3audio/mpegMPEGAudioStream,LayerIII*.mp4audio/mp4,video/mp4MPEG-4Audio/Video*.mpegvideo/mpegMPEGVideoStream,LayerII*.mpgvideo/mpegMPEGVideoStream,LayerII*.mppapplication/vnd.ms-projectMSProjectProject*.oggapplication/ogg,audio/oggOggVorbis*.pdfapplication/pdfPortableDocumentFormat*.pngp_w_picpath/pngPortableNetworkGraphics*.potapplication/vnd.ms-powerpointMSPowerPointTemplate*.ppsapplication/vnd.ms-powerpointMSPowerPointSlideshow*.pptapplication/vnd.ms-powerpointMSPowerPointPresentation*.rtfapplication/rtf,text/rtfRichTextFormat*.svfp_w_picpath/vnd.svfSimpleVectorFormat*.tifp_w_picpath/tiffTaggedImageFormatFile*.tiffp_w_picpath/tiffTaggedImageFormatFile*.txttext/plainPlainText*.wdbapplication/vnd.ms-worksMSWorksDatabase*.wpsapplication/vnd.ms-worksWorksTextDocument*.xhtmlapplication/xhtml+xmlExtensibleHyperTextMarkupLanguage*.xlcapplication/vnd.ms-excelMSExcelChart*.xlmapplication/vnd.ms-excelMSExcelMacro*.xlsapplication/vnd.ms-excelMSExcelSpreadsheet*.xltapplication/vnd.ms-excelMSExcelTemplate*.xlwapplication/vnd.ms-excelMSExcelWorkspace*.xmltext/xml,application/xmlExtensibleMarkupLanguage*.zipaplication/zipCompressedArchive
参考文章:
http://www.haorooms.com/post/input_file_leixing
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。