点击时如何更改按钮图像?

编程入门 行业动态 更新时间:2024-10-25 03:25:37
本文介绍了点击时如何更改按钮图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用图像和hrefs来创建按钮。代码如下所示:

I am using images and hrefs to create buttons. Code look like this:

<a href="www.zive.sk"><img src="res/images/zive.png" alt="Zive.sk" id="ziveCircle"></a>

如果用户按下按钮,是否有任何方法可以更改图像src?也许某些事件处理程序将确定用户已按下图像?它应该作为正常的按钮,所以当用户按下它并保持按下时,它应该改变图像src,当他释放按钮时,应该加载href(正常按钮行为)。

Is there any way to change image src if user press button? Maybe some event handler which will determine that user has pressed image? It should act as normal button so when user press it and keep pressed it should change image src and when he releases the button then the href should be loaded (normal button behaviour).

PS:我无法使用css。

PS: I cannot use css for this.

推荐答案

我找到了一个解决方案,使用了一些Hope I Helped脚本。这里是代码:

I have found a solution, using some of Hope I Helped script. Here is the code:

function buttons(){ document.getElementById('zive-anchor').onmousedown=function () { document.getElementById('ziveCircle').src = "res/images/zivePressed.png"; }; document.getElementById('zive-anchor').onmouseout=function () { document.getElementById('ziveCircle').src = "res/images/zive.png"; }; };

这里是HTML:

<div data-role="page" id="homepage"> <div id="selectCircle"> <a href="feeds.html#page1" rel="external" id="zive-anchor"><img src="res/images/zive.png" alt="Zive.sk" id="ziveCircle"></a>

更多推荐

点击时如何更改按钮图像?

本文发布于:2023-06-09 04:12:51,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   如何更改   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!