[英]How to append image into select option using javascript
請我需要幫助將圖像 src 附加到 javascript 中的選擇選項
這是我的代碼:
$.ajax({
type: "POST",
url: "http://10.102.220.119:8001/api/1/device/devices",
dataType: "json",
data: { ids : ids},
success:function(data){
for (var i = 0 ; i<data.length;i++){
var image = data[i].image;
var mime = data[i].mime;
var img = new Image();
img.src = "data:"+mime+";base64,"+image;
document.body.appendChild(img);
/*var option = document.createElement("option");
option.data-img-src = img.src;
var select = document.getElementById("selectImage");
select.appendChild(option);*/
}
}
});
我用
option.data-img-src = img.src;
但它顯示此錯誤:
Invalid left-hand side in assignment
請任何幫助
當對象的鍵包含-
您可以使用option["data-img-src"]
代替
嘗試(純javascript):
option.setAttribute('data-img-src', img.src);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.