H5文件操作(type="file")
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了H5文件操作(type="file")相关的知识,希望对你有一定的参考价值。
参考技术A
• name : 文件名,不包含路径。
• type : 文件类型。图片类型的文件都会以 image/ 开头,可以由此来限制只允许
上传图片。
• size : 文件大小。可以根据文件大小来进行其他操作。
• lastModified : 文件最后修改的时间。
input 中有个 accept 属性,可以用来规定能够通过文件上传进行提交的文件
类型。 accept="image/*" 可以用来限制只允许上传图像格式。但是在 Webkit 浏览器
下却出现了响应滞慢的问题,要等上好几秒才弹出文件选择框 。 解决方法就是将 * 通配符改为指定的 MIME 类型。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<input type="file" id="files" accept="image/gif,image/jpeg,image/jpg,image/png">
<script>
var elem = document.getElementById(\'files\');
elem.onchange = function ()
console.log(this.files)
</script>
</body>
</html>
Irrlicht_0.1源码学习—include/irrTypes.h & include/IeventReceiver.h
irrTypes.h这个文件做的事很简单,通过一系列typedef操作定义了Irrlicht引擎中的所有基本数据类型,以保证引擎的可移植性。
IeventReceiver.h则定义了一些用于事件系统中的枚举和结构/类。其中包含了EEVENT_TYPE、EMOUSE_INPUT_EVENT、EGUI_EVENT_TYPE三种枚举类型以及SEvent结构和IEventReceiver类。
EEVENT_TYPE:用于枚举irrlicht引擎中所有的事件类型(gui事件、鼠标事件、键盘事件)
//! Enumeration for all event types there are. enum EEVENT_TYPE { //! An event of the graphical user interface. EET_GUI_EVENT = 0, //! A mouse input event. EET_MOUSE_INPUT_EVENT, //! A key input evant. EET_KEY_INPUT_EVENT };
EMOUSE_INPUT_EVENT:用于枚举所有的鼠标输入事件
//! Enumeration for all mouse input events enum EMOUSE_INPUT_EVENT { //! Left mouse button was pressed down. EMIE_LMOUSE_PRESSED_DOWN = 0, //! Right mouse button was pressed down. EMIE_RMOUSE_PRESSED_DOWN, //! Middle mouse button was pressed down. EMIE_MMOUSE_PRESSED_DOWN, //! Left mouse button was left up. EMIE_LMOUSE_LEFT_UP, //! Right mouse button was left up. EMIE_RMOUSE_LEFT_UP, //! Middle mouse button was left up. EMIE_MMOUSE_LEFT_UP, //! The mouse cursor changed its position. EMIE_MOUSE_MOVED };
EGUI_EVENT_TYPE:用于枚举所有由gui系统投递出的事件
//! Enumeration for all events which are sendable by the gui system enum EGUI_EVENT_TYPE { //! A gui element has lost its key focus. EGET_ELEMENT_KEY_FOCUS_LOST = 0, //! A gui element has lost its mouse focus. EGET_ELEMENT_MOUSE_FOCUS_LOST, //! A gui element was hovered. EGET_ELEMENT_HOVERED, //! A button was clicked. EGET_BUTTON_CLICKED, //! A scrollbar has changed its position. EGET_SCROLL_BAR_CHANGED, //! A checkbox has changed its check state. EGET_CHECKBOX_CHANGED, //! A new item in a listbox was seleted. EGET_LISTBOX_CHANGED, /! An item in the listbox was selected, which was already selected. EGET_LISTBOX_SELECTED_AGAIN, };
SEvent:用于储存各类事件相关数据的结构体,其实现中使用union优化内存占用情况
//! Struct for holding event data. An event can be a gui, mouse or keyboard event. struct SEvent { EEVENT_TYPE EventType; union { struct { gui::IGUIElement* Caller; gui::EGUI_EVENT_TYPE EventType; } GUIEvent; struct { s32 X, Y; // mouse positions; EMOUSE_INPUT_EVENT Event; } MouseInput; struct { s32 Key; // TODO key bool PressedDown; // if not pressed, then left up } KeyInput; }; };
IEventReceiver:所有能够接收事件的对象必须实现的接口类,内部声明了一个处理各类事件的纯虚函数(OnEvent)
//! Interface of an object wich can receive events. class IEventReceiver { public: //! called if an event happened. returns true if event was processed virtual bool OnEvent(SEvent event) = 0; };
以上是关于H5文件操作(type="file")的主要内容,如果未能解决你的问题,请参考以下文章