Javascript 更改multipe映像的映像src

Javascript 更改multipe映像的映像src,javascript,html,image,button,src,Javascript,Html,Image,Button,Src,这是我的HTML: <img class="image" src="" /> <img class="image" src="" /> <img class="image" src="" /> <button onclick="changeImages()">Change the images</button> 我怎样才能使我的代码在我点击按钮时,所有的图像都会改变 谢谢返回一组没有应用属性方法的元素。您需要遍历集合,并将所需的属性应

这是我的HTML:

<img class="image" src="" />
<img class="image" src="" />
<img class="image" src="" />
<button onclick="changeImages()">Change the images</button>
我怎样才能使我的代码在我点击按钮时,所有的图像都会改变

谢谢

返回一组没有应用属性方法的元素。您需要遍历集合,并将所需的属性应用于集合中的每个项。比如:

document.getElementsByClassName("image").forEach(function(image) {
    image.setAttribute("src", "images/image.png");
});
返回一组没有应用属性方法的元素。您需要遍历集合,并将所需的属性应用于集合中的每个项。比如:

document.getElementsByClassName("image").forEach(function(image) {
    image.setAttribute("src", "images/image.png");
});