HTML 网页中的 OnClick 图片源发生了变化,但移动端没有变化
HTML OnClick image source changes in web, but not mobile
我正在使用 Elementor 块生成器在 Wordpress 中工作,我正在尝试将一个 .gif 图像的源切换到另一个 .gif 图像。我的 OnClick 事件在网络上运行良好,但在移动设备上运行不正常。我无休止地搜索并确保另一个元素没有阻止触摸事件,添加了 OnTouch 等但无济于事。
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif"
onClick="this.src='https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif'">
将onClick
改为onclick
:
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif"
onclick="this.src='https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif'">
出于 these 的原因,我还建议不要使用 onclick
属性,而是使用 addEventListener
。
document.getElementById("image").addEventListener("click", function() {
this.src = "https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif";
});
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif" id="image">
我正在使用 Elementor 块生成器在 Wordpress 中工作,我正在尝试将一个 .gif 图像的源切换到另一个 .gif 图像。我的 OnClick 事件在网络上运行良好,但在移动设备上运行不正常。我无休止地搜索并确保另一个元素没有阻止触摸事件,添加了 OnTouch 等但无济于事。
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif"
onClick="this.src='https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif'">
将onClick
改为onclick
:
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif"
onclick="this.src='https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif'">
出于 these 的原因,我还建议不要使用 onclick
属性,而是使用 addEventListener
。
document.getElementById("image").addEventListener("click", function() {
this.src = "https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1D.gif";
});
<img src="https://lowlifeclothing.co/wp-content/uploads/2020/09/Loop1.gif" id="image">