Javascript 上传后未显示图像

Javascript 上传后未显示图像,javascript,html,css,web,Javascript,Html,Css,Web,我有一个自定义文件选择按钮,我添加了一个JavaScript文件,用于在用户选择图像后预览它。但似乎有点不对劲,上传后我无法预览。有人能帮忙吗?谢谢 //HTML <div class="container"> <div class="content"> <div class="box"> <input type='file' accept=".gif,.png,

我有一个自定义文件选择按钮,我添加了一个JavaScript文件,用于在用户选择图像后预览它。但似乎有点不对劲,上传后我无法预览。有人能帮忙吗?谢谢

//HTML

<div class="container">

            <div class="content">

            <div class="box">
                    <input type='file' accept=".gif,.png,.jpg,.jpeg" name="file-7[]" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple onchange="readURL(this);"/>
                    <label for="file-7"><span></span> <strong><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> Choose a Ad&hellip;</strong></label>
                    <img id="blah" src="#" alt="your image" />
                    <div class = "forms">

<form id="contact_form" action="#" method="POST" enctype="multipart/form-data">

    <div class="row">



    <input id="submit_button" type="submit" value="Post Ad" />
</form>     
</div>



                </div>
            </div>
        </div>

很抱歉缩进不好。

对我有效,你确定添加了jQuery(或重写为vanilla js)吗?我的错,忘记添加jQuery了。谢谢;)
 alert("Hello! I am an alert box!!");
 function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#blah')
                    .attr('src', e.target.result)
                    .width(150)
                    .height(200);
            };

            reader.readAsDataURL(input.files[0]);
        }
    }