我有一个网页,我在其中使用 var img = document.createElement("img");
创建图像标签,但在下一行中我还使用了元素高度和宽度,但它不能正常工作:
var base64_string = response.response.data[i].data;
var img = document.createElement("img");
// added `width` , `height` properties to `img` attributes
img.css({
'width' : '100px',
'height' : '100px'
});
img.src = "data:image/jpeg;base64," + base64_string;
var preview = document.getElementById("images");
preview.appendChild(img);
为什么高度和宽度在此代码中不起作用?请给我一些建议。
最佳答案
DOM 中没有css()
方法。您似乎将它与 jQuery 混淆了。
您可以改为修改图像元素的 .style.width
和 .style.height
属性。
关于jquery - 为什么网页上没有显示高度和宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53630755/