猿问

各位大佬我试着做了个随机抽奖的小东西数组里原本是文本后来试着换成图片后加载不了啊怎么回事啊

http://img.mukewang.com/587f75b00001539419201029.jpghttp://img.mukewang.com/587f75b20001b0d719161037.jpg这运行后图片全部加载不出来怎么破啊

我原本是想把图片的路径放进数组里然后再获取我那个背景图<img id="start> ,$("#start") 然后就用随机数获取数组地下标来获取数组里的元素,然后就用attr()来替换#start里面地“src" 另外一个参数就用随机数的数组

可为什么图片就是加载不出来呢QWQ

<!DOCTYPE html>

<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>jquery随机抽奖 </title>

<head>

<script type="text/javascript" src="jq/jquery-3.1.1.js"></script></script>

<script type="text/javascript">

$(function(){

var alldata = new Array("img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg");

var num = alldata.length - 1;

var start = $("#start");

var btn = $("#btn");

var open = false;

function change(){

var randomVal = Math.round(Math.random() * num);

var prizeName = alldata[randomVal];

start.attr("src","prizeName");

}

function run(){

if(!open){

timer=setInterval(change,30);

btn.removeClass('start').addClass('stop').text('停止');

open = true;

}else{

clearInterval(timer);

btn.removeClass('stop').addClass('start').text('开始抽奖');

open = false;

}

}

btn.click(function(){run();})

})

</script>

<style>

body{ background:#fff;}

.wrap{ width:300px; margin:100px auto; font-family:"微软雅黑";}

.show{ width:300px; height:300px; background-color:#ff3300; line-height:300px; text-align:center; color:#fff; font-size:28px; -moz-border-radius:150px; -webkit-border-radius:150px; border-radius:150px; background-image: -webkit-gradient(linear,0% 0%, 0% 100%, from(#FF9600), to(#F84000), color-stop(0.5,#fb6c00)); -moz-box-shadow:2px 2px 10px #BBBBBB; -webkit-box-shadow:2px 2px 10px #BBBBBB; box-shadow:2px 2px 10px #BBBBBB;overflow: hidden;}

.btn a{ display:block; width:120px; height:50px; margin:30px auto; text-align:center; line-height:50px; text-decoration:none; color:#fff; -moz-border-radius:25px; -webkit-border-radius:25px; border-radius:25px;}

.btn a.start{ background:#80b600;}

.btn a.start:hover{ background:#75a700;}

.btn a.stop{ background:#00a2ff;}

.btn a.stop:hover{ background:#008bdb;}

</style>

</head>


<body>

<div class="wrap">

<div class="show" id="show"><img id="start" src="img/1.jpg"></div>

<div class="btn">

<a href="javascript:void(0)" class="start" id="btn">开始抽奖</a>

</div>

</div>

<div style="text-align:center;clear:both">

<p>适用浏览器:IE8、360、FireFox、Chrome、Opera、傲游、搜狗、世界之窗. 不支持Safari浏览器。</p>

</div>

</body>

</html>


无节操司机
浏览 1361回答 1
1回答

MarlboroKay

报错是图片找不到,建议你仔细查一下图片路径那块
随时随地看视频慕课网APP
我要回答