易网时代-编程资源站
Welcome
微信登录
编程资源
图片资源库
蚂蚁家优选
PDF转换器
软件资源
软件开发
、
小程序制作
、
系统集成与运维
、
空间租用
、
硬件开发
、
视频监控
、
技术咨询与支持
——联系电话:0311-88999002/88999003
首页
/
操作系统
/
Linux
/
jQuery通过设置元素的属性实现图片随机切换
jQuery通过设置元素的属性实现图片随机切换:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<head>
<title>
设置元素的属性(二)
</title>
<script
type
=
"text/javascript"
src
=
"../Jscript/jquery-1.4.2.js"
>
</script>
<script
type
=
"text/javascript"
src
=
"../Jscript/jquery-1.4.2-vsdoc.js"
>
</script>
<style
type
=
"text/css"
>
body {
font-size: 12px
}
.clsSpn {
float: left;
padding-top: 10px;
padding-left: 10px
}
.clsImg {
border: solid 1px #ccc;
padding: 3px;
float: left
}
</style>
<script
type
=
"text/javascript"
>
$(function() {
$("img").attr("src", function() {
return "../Images/img0" + Math.floor(Math.random() * 2 + 1) + ".jpg"
}); //设置src属性 通过随机生成数字。。。因此每次生成的Src都不同,从而实现页面上图片的随机切换。
$("img").attr("title", "这是一幅风景画"); //设置title属性
$("img").addClass("clsImg"); //增加样式
})
</script>
</head>
<body>
<img
alt
=
""
src
=
"../Images/img03.gif"
style
=
"float: left"
/>
</body>
</html>
收藏该网址
版权所有©石家庄振强科技有限公司2024
冀ICP备08103738号-5
网站地图