Javascript:使用mouseover / mouseout启用/禁用按钮 [英] Javascript: enable/disable button with mouseover/mouseout

查看:786
本文介绍了Javascript:使用mouseover / mouseout启用/禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该非常简单:

< input type =buttonname =testid =testvalue = 滚过我onmouseover =this.disabled = true; onmouseout =this.disabled = false;>

如果我将鼠标光标放在此按钮上,它将被禁用.. !
但现在当我移出光标时,它没有启用...嘘。

If I place the mouse cursor over this button, it gets disabled..yay! But now when I move the cursor out, it doesn't get enabled...boo.

我理解禁用它的概念意味着你可以'用它做任何事情。但是如何通过鼠标启用它?可能吗?我错过了什么吗?

I understand the concept of disabling it means you can't do anything with it. But how do you get it to be enabled with a mouse out? Is it possible? Am I missing something?

推荐答案

你应该将mouseout设置为 disabled =''而不是。

You should set the mouseout to disabled = '' instead.

<input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;" onmouseout="this.disabled='';">

禁用的财产只会查看它是否存在。您可以设置disabled ='anything',它将被禁用。过去,您只需要在属性中使用关键字禁用,但对于有效的XHTML,您需要将每个属性设置为等于某事。

The disabled property only looks to see if it's there at all. You can set disabled='anything' and it will be disabled. It used to be that you only needed the keyword disabled in your attributes but for valid XHTML you need to set every attribute equal to something.

编辑:
我稍微玩了一下,并在 SPAN 标签上加了一些填充物允许事件正常工作。没有填充,它不会捕获事件,因为输入按钮被禁用。我刚刚将背景设置为红色,因此很容易看到 SPAN 用完的区域。

I played around with this a little bit and added some padding to the SPAN tag and it allows the events to work properly. Without padding, it's not trapping the events because the input button is disabled. I just made the background red so it was easy to see the area the SPAN used up.

<span style="padding: 8px; background: red;"  onmouseout="this.firstChild.disabled='';"><input type="button" name="test" id="test" value="roll over me" onmouseover="this.disabled=true;"></span>

这篇关于Javascript:使用mouseover / mouseout启用/禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆