Front-end image upload image preview

<!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>
    <script src="jquery-2.1.1.min.js"></script>
    <script>
    $(function(){
        $('.file').change(function(){
        $filePath=URL.createObjectURL(this.files[0]);
        $('img').attr('src',$filePath);
        })
    })
    </script>
</head>
<body>
    <input type="file" class="file">
    <br>
    <img src="" alt="">
</body>
</html>

Front-end style

<img height="30px" src="${pageContext.request.contextPath}/static/imgs/${c.pic_name}" class="imgs">
<input type=file id=browsefile style="visibility:hidden" onchange=filename.value=event.target.files[0].name class="file">
<input type=textfield id=filename>
<input type=button id=filebutton value=browser onclick="browsefile.click()">

Very practical, watching the changing needs of it

Guess you like

Origin blog.csdn.net/nuoyuezuo/article/details/88617431