How can I set Image source with base64

后端 未结 4 1890
抹茶落季
抹茶落季 2020-11-27 13:57

I want to set the Image source to a base64 source but it does not work:

JSfiddle.net/NT9KB


the Ja

4条回答
  •  暖寄归人
    2020-11-27 14:46

    Try using setAttribute instead:

    document.getElementById('img')
        .setAttribute(
            'src', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
        );
    

    Real answer: (And make sure you remove the line-breaks in the base64.)

提交回复
热议问题