我希望在点击图片后包含我的图片尺寸, 目前它们显示得比我希望它们显示的要大。
示例:http://messaages.com/post/144951542174
HTML:https://gist.github.com/anonymous/4f09e3306f9b28ee0dce286342c51c7e
我在代码中尝试过各种大小,但我似乎无法更改它。
最佳答案
如果您想在点击图片后更改图片大小,您需要使用 javascript 来更改 css。
<img onclick="imageChange(this)" style="width: 200px; cursor: pointer;" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
<script>
window.imageChange = function(image) {
if (image.style.width === "200px") {
image.style.width = "100px";
} else {
image.style.width = "200px";
}
}
</script>
JS fiddle :https://jsfiddle.net/ws12fqzc/
关于html - 单击后包含 HTML 图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37556418/