简体   繁体   English

JavaScript HTML,来自IMG标签的可点击按钮

[英]JavaScript HTML, clickable button from IMG tag

I am trying to do a clickable button with javascript. 我想用javascript做一个可点击的按钮。 I am doing the following 我正在做以下事情

document.getElementById("nav").onmousedown = function() { this.src="img1.png"; return false;}
document.getElementById("nav").onmouseout = function() { this.src="img.png"; return false;
}

What am I missing with events? 事件中我错过了什么? By the way, I did it before by encapsulating events in single initAll foo makes the button clickable but slow on the server.... When I click it opens the link before I see my button pressed animation... Any info? 顺便说一句,我之前通过在单个initAll封装事件来做到这initAll foo使得按钮可点击但在服务器上很慢....当我点击它之前打开链接我看到我的按钮按下动画...任何信息?

Do you really want to use javascript here? 你真的想在这里使用javascript吗? Maybe CSS will fit your needs better? 也许CSS会更好地满足您的需求?

#nav {
    background: url('img1.png') no-repeat 0 0;
}
#nav:active {
    background: url('img2.png') no-repeat 0 0;
}

您是否尝试过使用jquery的.animate,然后在回调函数中将用户发送到链接?

尝试更换thisdocument.getElementById("nav")看看它做任何事情。

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

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