使用javascript将图片添加到选项中

时间:2019-02-27 14:13:33

标签: javascript html

我正在使用Firebase!因此决定将检索到的数据放在datalist元素中,并将图像添加到选项值旁边,如下所示:

enter image description here

我设法将检索到的数据放在datalist选项中!问题出在我尝试设置option.value="<img src=.....>“但不起作用的图像上,我也尝试设置option.style='background-img:url()'也不起作用

这是我的代码:

 var databaseRef = firebase.database().ref('titres/');
        databaseRef.once('value', function(snapshot) {
        snapshot.forEach(function(childSnapshot) {
        var childKey = childSnapshot.key;
        var childData = childSnapshot.val();
        const list = document.getElementById('select');
        [childKey].forEach(item => {
          let x = document.createElement("IMG");
          x.src=childData.URL_logo;
          let option = document.createElement('option');
          option.value = item;   
          option.text= x;
          option.style="";
          list.appendChild(option);
        });

有什么主意吗?

0 个答案:

没有答案