jQuery 随机切换图片的例子
发布时间:2015-11-14 编辑:jiaochengji.com
分享一个jQuery 随机切换图片的小例子,学习jquery中随机函数random的用法,有需要的朋友可以看看。
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>jquery 随机切换图片-www.jbxue.com</title>
<style type="text/css">
img
{
width:200px; height:200px;
}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btn1').click(function () {
var num = Math.floor(Math.random() * 8 + 1);
$('img').attr('src','picture/'+num+'.jpg')
})
})
</script>
</head>
<body>
<img src="picture/1.jpg" id="img1" />
<input id="btn1" type="button" value="变换" />
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jquery 随机切换图片-www.jbxue.com</title>
<style type="text/css">
img
{
width:200px; height:200px;
}
</style>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btn1').click(function () {
var num = Math.floor(Math.random() * 8 + 1);
$('img').attr('src','picture/'+num+'.jpg')
})
})
</script>
</head>
<body>
<img src="picture/1.jpg" id="img1" />
<input id="btn1" type="button" value="变换" />
</body>
</html>
您可能感兴趣的文章:
jQuery 随机切换图片的例子
jQuery随机切换图片的小例子
40个有创意的jQuery图片和内容滑动及弹出插件收藏集之三
40个有创意的jQuery图片、内容滑动及弹出插件收藏集之一
jquery幻灯片特效banner切换实例
jQuery 随机展示图片的例子
php生成随机数的例子
Jquery 随机刷新页面背景图片
JS随机效果之随机广告(显示图片)的代码
jQuery图片效果切换 Adipoli
上一篇:jquery 表格排序实例详解
下一篇:jQuery 随机展示图片的例子
[关闭]