search

Home  >  Q&A  >  body text

javascript - Regarding the issue of calling the camera interface on the WeChat webpage to display pictures?

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梦2838 days ago669

reply all(2)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:45:05

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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-19 10:45:05

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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    <code><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></code>

    reply
    0
  • Cancelreply