首页 > Web开发 > 详细

js和jquery 两种写法 鼠标经过图片切换背景效果

时间:2015-10-12 11:55:46      阅读:189      评论:0      收藏:0      [点我收藏+]

这个是javascript的写法

<img src="res/img/shop-c_32.jpg"  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>

我比较倾向于后者的写法。那大家觉得呢?

js和jquery 两种写法 鼠标经过图片切换背景效果

原文:http://www.cnblogs.com/alone2015/p/4870955.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!