0

我做了这个代码:

<!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> <script src="http://code.jquery.com/jquery-1.8.2.js"></script> <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <script> setInterval(function(){chrono('t');},1000); </script> <?php include('function.php'); session_start(); global $list; $list= captcha_list($_SESSION['id']); global $i; $i=0; ?> <script> function chrono(id){ inte= parseInt(document.getElementById(id).innerHTML,10); switch(inte) { case 0: document.getElementById(id).innerHTML='7'; break; case 1: document.getElementById(id).innerHTML='0'; document.getElementById('im').src="<?php echo $list[$i]['captcha'];?>" ; break; case 2: document.getElementById(id).innerHTML='1'; break; case 3: document.getElementById(id).innerHTML='2'; break; case 4: document.getElementById(id).innerHTML='3'; break; case 5: document.getElementById(id).innerHTML='4'; break; case 5: document.getElementById(id).innerHTML='4'; break; case 6: document.getElementById(id).innerHTML='5'; break; case 7: document.getElementById(id).innerHTML='6'; <?php $i++; ?> break; default: break; } }; </script> <body style="background-image:url(paper_03.png)" > <form name="form_2" style="background-image:url(paper_02.png);position: absolute; top:30px; left: 200px; width: 500px; height: 500px;" > <CENTER> <table style="position: relative; top:30px;" > <tr><td colspan=4><label>Image will be refresh in <label id="t" name="t"> 7 </label> seconds </label></td><td></td></tr> <tr><td height=200px ><label>Image </label></td><td></td><td height=200px colspan=2><input type="image" id="im" src="<?php echo $list[$i]['captcha'];?>" style=" height=150px" /> </td></tr> <tr><td height=200px><label>Text </label></td><td colspan=3 height=200px><input type="text" name="cap" style="width: 400px" /> </td></tr> <tr><td></td><td><input type="submit" name="answer" value="SUBMIT ANSWER" style="height:200%;background-image:url(paper_03.png)"/> </td><td><input type="submit" name="know" value="DON'T KNOW" style="height:200%; background-image:url(paper_03.png)"/> </td><td><input type="submit" name="pause" value="SUBMIT AND PAUSE" style="height:200%;background-image:url(paper_03.png)"/> </td> </tr> </table> </CENTER> </form> </body> <footer> <?php include('header_footer/footer.php'); ?> </footer> </html>

问题是显示的第一个图像是数组中的第二个图像,而第三个图像永远不会显示。变化是当 timer=7 和 timer=0 时。

  • 错误在哪里?
  • 这是什么原因?
  • 我该如何解决?
4

1 回答 1

0

这将更改图像 src。这是你想要的吗?

var inte = 0;
setInterval(chrono,1000);

function chrono(){
  inte++;
  if(inte > 7) inte = 0;
  document.getElementById('im').src="paper_0" + inte + ".png";
};
于 2012-12-29T18:02:59.257 回答