[英]Resize all images with javascript
如何使用 javascript 調整所有圖像的大小? 我試過這個:
var images = document.getElementByTagName('img')
images.max_width = '100px'
images.max_height = '100px'
但它沒有用。 然后我嘗試了document.images
而不是document.getElementByTagName('img')
但它也沒有用。
另外,我不想使用 CSS 調整圖像大小。 請回復。
謝謝。
使用 forEach() 或 for() 循環遍歷所有圖像。
// select all images
var images = document.querySelectorAll('img');
// loop through all images
images.forEach(function (img, i) {
img.style.maxWidth('100px');
img.style.maxHeight('100px');
});
如果您不希望圖像改變寬度/高度,則給它們一個寬度:100px; 和高度:100px;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.