简体   繁体   English

HTML OnClick 图像源在 Web 中更改,但在移动设备中没有更改

[英]HTML OnClick image source changes in web, but not mobile

I'm working in Wordpress with the Elementor block builder and I'm trying to have a .gif image switch sources to another .gif image.我正在使用 Elementor 块构建器在 Wordpress 中工作,并且我正在尝试将 .gif 图像切换源到另一个 .gif 图像。 The OnClick event I have works perfectly fine via web, but not mobile.我的 OnClick 事件通过网络运行得非常好,但不适用于移动设备。 I've searched endlessly and have made sure another element is not blocking the touch event, added OnTouch, etc but to no avail.我无休止地搜索并确保另一个元素没有阻止触摸事件,添加了 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'">

Change onClick to onclick :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'">

I also recommend not using the onclick attribute and instead using addEventListener for these reasons.由于这些原因,我还建议不要使用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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM