我想用js写图片点击后放大的效果,我写完的没有效果,求助

我实在弄不懂啊,怎么写才对
2025-03-10 19:48:34
推荐回答(1个)
回答1:





放大和缩小


window.onload = function(){

var image = document.getElementById("testImg");
image.onclick = function() {
var width = parseInt(this.width);
if(width == 750) {
this.width = 200;
this.height = 180;
} else {
this.width = 750;
this.height = 536;
}
}
};








var image2 = document.getElementById("testImg2");
image2.onclick = function() {
var width = parseInt(this.width);
if(width == 1024) {
this.width = 512;
this.height = 340;
} else {
this.width = 1024;
this.height = 685;
}
};