当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery随机切换图片的小例子

jQuery随机切换图片的小例子

2018年10月22日  | 移动技术网IT编程  | 我要评论

代码如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "https://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<title></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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网