js和jquery 两种写法 鼠标经过图片切换背景效果
2024-09-06 15:58:53
这个是javascript的写法
<img src="res/img/shop-c_32.jpg" alt="" onmouseover="this.src='res/img/shop-c_29.jpg';" onmouseout="this.src='res/img/shop-c_32.jpg';">
这是个jquery的写法
<img src="res/img/shop-c_32.jpg" data-back="res/img/shop-c_29.jpg">
再加上jquery的效果写法
<script>
$("img[data-back]").hover(function(){
$(this).data('fallback',$(this).attr('src'));
$(this).attr('src',$(this).data('back'));
},function(){
$(this).attr('src',$(this).data('fallback'));
}); </script>
我比较倾向于后者的写法。那大家觉得呢?
最新文章
- rhel 7.0 配置centos yum源(2016/12/8),成功!
- JavaScript 深入了解基本类型和引用类型的值
- 简单的DropDownButton(Winform)
- linux 定时清理session
- bpl 包的编写和引用
- POJ 3461 裸的KMP
- iOS web与js的简单交互
- gis论坛
- information_schema.collation_character_set_applicability 学习
- scrapy pipelines导出各种格式
- golang-http-post
- [C++]2-5 分数化小数
- MyBatis 源码分析 - 配置文件解析过程
- JavaSE-关键字final
- go自动补全
- (22)bootstrap 初识 + Font Awesome(字体图标库)
- pig—WordCount analysis
- Redis 基础操作
- 关于Socket和ServerSocket类详解
- 通过mongodump和mongorestore实现Mongodb备份和恢复