javascript - Regarding the issue of calling the camera interface on the WeChat webpage to display pictures?
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:43:05
0
2
584

After I call WeChat's image selection or camera interface to get the localId of the image, can I display the image through <img src=localId>?
If not, how should I display the image?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
曾经蜡笔没有小新

Thanks for the invitation, yes. It is available in the WeChat demo. The localid can be displayed directly in src.

洪涛

I don’t know if the WeChat interface will work. But the code below will definitely work

<input type="file" accept="image/*" value="点击上传" onchange="preview($event)"/>
<img src="" id="previewImg">
<script>
    function preview($event) {
        const $target = $event.target
        if ($target.files && $target.files[0]){
            const reader = new FileReader();
            reader.readAsDataURL($target.files[0]);
            reader.onload = function(evt){
                document.getElementById('previewImg').setAttribute('src', evt.target.result)
                // 上传
                // 向服务器发送$target.files[0]
            }

        }
    }
</script>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!