主题:  鼠标行为:经过文本输入区域改变背景色的实现?

Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#12004/12/15 0:05:04
一个页面有若干文本输入区域,当鼠标经过文本输入区域时,该区域背景色改变[文本输入区域,而非<td>]

不知道用JS脚本实现比较好,还是用CSS实现比较好

望能够说明具体实现方法,感谢~



沉默是金

职务:普通成员
等级:6
金币:11.2
发贴:4357
#22004/12/15 0:45:39
JS+CSS

[Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]


难人一个……

Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#32004/12/15 23:17:19
明白了,和<td>的实现方法相同,昨天我也尝试这么做过,结果没成功,以为方法有区别,可能是粗心的脚本错误吧
不过彻底明白了 感谢



Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#42004/12/15 23:28:38
想减少代码冗余,将这些效果做在css.css文件中应该如何写?
如:
.infotxt {
    font-size: 12px;
    color: #000000;
    border-top-width: thin;
    border-bottom-width: thin;
    border-top-style: dashed;
    border-right-style: none;
    border-bottom-style: dashed;
... ...
}
假设想把那个效果加在上面的代码中,应该怎么写呢?
我试过:
onMouseOver="this.style.background='#ff0000'";
onMouseOut="this.style.background='#efefef'";
但是不行啊



不是高手

职务:普通成员
等级:3
金币:5.0
发贴:1352
#52004/12/16 13:41:41
this.className="infortext"

还有你语法有问题,onmouseover="this.style.backgroundColor='#FF0000'"



Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#62004/12/16 15:09:24
不是不是 aquarior 误会了
按找你第一次给我的代码
onMouseOver="this.style.background='#ff0000'";
将这句加在文本输入区域属性中起作用,效果可以实现的

我是想问如果把这句加在CSS中应该怎样去写?
譬如:
xxx: xxx;
因为我看见CSS中的语句几乎都是这样的
.infotxt {
font-size: 12px;
color: #000000;
border-top-width: thin;
border-bottom-width: thin;
border-top-style: dashed;
border-right-style: none;
border-bottom-style: dashed;
... ...
}
我是想把那个鼠标行为的效果加在这个infotxt的CSS样式中,但不知道正确的语法格式
我试过直接将代码onMouseOver="this.style.background='#ff0000'";插入到infotxt样式中但不起作用,后来又试了一下onMouseOver"this.style.background='#ff0000'";但也不行~
我想知道它是否可以加在CSS样式中,正确的书写格式应该是怎样的?



vickie_5d

职务:普通成员
等级:3
金币:2.0
发贴:946
#72004/12/16 16:06:25
<style type="text/css">
input {vickie: expression(onmouseover=function()
{this.style.backgroundColor="#FF0088"},
onmouseout=function(){this.style.backgroundColor="#ffaacc"}) }
</style>
試試看~~



Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#82004/12/16 23:35:54
谢谢你啊,不过语法格式好象还是不对~!



不是高手

职务:普通成员
等级:3
金币:5.0
发贴:1352
#92004/12/17 8:01:08
.infotxt {
font-size: 12px;
color: #000000;
border-top-width: thin;
border-bottom-width: thin;
border-top-style: dashed;
border-right-style: none;
border-bottom-style: dashed;
background-color:#FF0000
}



vickie_5d

职务:普通成员
等级:3
金币:2.0
发贴:946
#102004/12/17 10:33:37
爲什麽錯了呢?暈。



Youngson

职务:普通成员
等级:1
金币:0.0
发贴:89
#112004/12/20 13:08:36
vickie在上个帖子中说
引用:
爲什麽錯了呢?暈。


你的方法我试过有效果。没有错。



vickie_5d

职务:普通成员
等级:3
金币:2.0
发贴:946
#122004/12/20 13:12:48
瀏覽器助手給遮擋住了,去掉那個,就好用了:)



Server

职务:普通成员
等级:1
金币:0.0
发贴:97
#132005/3/11 11:09:12
不好意思,那时候不懂~! 呵呵 ,现在懂点了 ~!