Method of generating images on the page

开发工具与关键技术:vs2015  MVC
作者:陈星宇
撰写时间:2019.5.15

First, let's create two labels, one input img tag is a label, while the img src tag is empty, we need to select the uploaded images, only to set the src attribute, another label is the input tag, we can by input of the tag file attributes, select the uploaded files.
Here Insert Picture Description
Then we write a method by clicking on the img tag to click on the file input tag attributes to achieve the selected pictures
Here Insert Picture Description
and then we read the new object is a file, then use regular expressions to determine whether it is uploaded over the image type.
Here Insert Picture Description
When these preparations after well, we write the change event of a change, when we click on the picture, input select the file will trigger numerical input label change after we choose a picture, after a change we can choose pictures on our img tag.
In the process of change, we have to get to upload the picture type, and then using the above write regular statements to determine whether the judgment is that we need the type of picture.
When these conditions are passed, we call our new FileReader that a method of readAsDataURL set url is popular path.
Here Insert Picture Description
This time we've got to upload url, then we load a onload event set to the src image url, then we choose the picture on the page is generated.
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/tianxiu11/article/details/90245018