Store, read, clear data (localStorage and file)

//储存
 localStorage.setItem('exam_name', exam_name);
 //读取
 localStorage.getItem('exam_name');
 //清除指定key
 localStorage.removeItem('exam_name')
 //清除所有
 localStorage.clear();

In the input of the file, the uploaded file will be saved in the files attribute. The files attribute saves an array, which saves the file body information, including the name, size, and other
Insert picture description here
commonly used information such as size. name and type

Create a FileReader in js to read file information. This object has the following common methods:

readAsBinaryString(file) read the file as binary code
readAsDataURL(file) read the file as DataURL
readAsText(file,[encoding format (optional)]) read the file as text

Reading small files (pictures, audios, small videos, etc.) commonly used readAsDataURL method, (we don’t understand the mechanism)
The following are a few commonly used trigger events, and a callback function is required later, and the parameters in the callback function are the created files Object

onabort Triggers
onerror when an error occurs. Triggers
onload when an error occurs . Triggers
onloadend when the file is successfully read. Onloadend Triggers when reading is complete, regardless of success or failure.
Onloadstart Triggers when reading starts. Onprogress is
reading.

The read result will be saved in the object e.target.result, if it succeeds, it will be the information read, if it is not read, it will be null (failure)

Guess you like

Origin blog.csdn.net/qq_50646256/article/details/112912552