Getting the result object of FileReader()

后端 未结 2 2032
攒了一身酷
攒了一身酷 2021-01-29 09:00

is there any way i can fetch the result object of a FileReader() without getting through a function ?

i have made a sample code below:

HTML

2条回答
  •  深忆病人
    2021-01-29 09:20

    The FileReader is asynchronous, so logic execution continues on past the load event handler while it waits for the file to be read. This means that (as with any async handler) all code reliant on the async event must be placed within the event handler. Try this:

    var reader = new FileReader();
    reader.onload = function() {
        code = reader.result;
        $("div").append(" 
    "); $("div").append("
    "); }; reader.readAsDataURL(upload);

提交回复
热议问题