Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2506769
  • 博文数量: 153
  • 博客积分: 8010
  • 博客等级: 中将
  • 技术积分: 1680
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-02 10:43
个人简介

IT精英-请移步http://www.ithtu.com

文章分类

全部博文(153)

文章存档

2011年(3)

2010年(5)

2009年(17)

2008年(20)

2007年(76)

2006年(32)

我的朋友

分类:

2007-08-24 17:34:17

问题说明: 用过css样式我们就知道, 可以定义一批对象的class属性来指定同一个样式来统一界面. 但如何统一同类型的对象的事件? 比如:界面有无数个 如何实现鼠标经过此图片, 图片的src变成是**_over.jpg?


解决方法: 使用css的expression方法,
具体实现要看看.css的写法:

/*替换图片CSS*/
#imgScript { /*这里使用对象ID来通配样式, 也可以定义一个css函数*/
star:expression(
onmouseover = function()
{
/*替换图片*/
if(this.hover != null){
this.name = this.src;
this.src = this.src.replace('.jpg', '_over.jpg');
this.HasChg = 1;
}
},
onmouseout = function()
{
/*还原本来的图片*/
if(this.HasChg != null){
this.src = this.name;
this.HasChg = null;
}
}
)

}/*end imgScript*/

应用样式的img:


请将鼠标放在a.jpg上看看效果

阅读(375) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~