先看看代码  randnum.php
<?php
session_start(); 
$arr2=range(0,9);
$arr3=range("A","Z");
$arr=array_merge($arr2,$arr3);
$keys=array_rand($arr,6);
$str=" ";
foreach($keys as $i)
$str.=$arr[$i];
$_SESSION["randValid"]=$STR;
header("Content-type: image/png");
$im = @imagecreatetruecolor(70,30)
or die("Cannot Initialize new GD image stream");for ($i=1;$i<10;$i++){
$line_color =  imagecolorallocate($im,rand(0,156),rand (0,156), rand(0,156));
imageline($im,rand(0,70),rand(0,30),rand(0,70),rand(0,30),$line_color);
}$text_color = imagecolorallocate($im,rand(0,255), rand(0,255), rand(0,255));
imagestring($im, 5,3, 5, $str, $text_color);
imagepng($im);
imagedestroy($im);
?> 在看一下调用方法
<html><script language="javascript">
function RefreshImage()
{
   var el =document.getElementById("unum");
   el.src='include/randnum.php';//这个特别重要
}
</script>
<body>
<input  type="text"  name="unum" id="unum"  size="10"  maxlength=4 />*
<img  src="include/randnum.php" title="单击刷新" style="cursor:pointer"  onMouseUp=" RefreshImage()" />
<span>点击图片刷新</span></body>
</html>那个地方错了。  能够出现验证码, 但无法实现点击刷新

解决方案 »

  1.   

      el.src='include/randnum.php';//这个特别重要
    這個僅僅是修改了src的地址並沒有真正刷新了頁面吧?需要增加onclick事件.
      

  2.   

    名为 unum 的 id 在哪里?
    <input  type="text"  name="unum" id="unum"  size="10"  maxlength=4 />
    目标都搞错了,结果怎么能正确呢?
      

  3.   

    你的js里只有img标签才能改变src,input没有src属性。<img  src="include/randnum.php" id="unum1" title="单击刷新" style="cursor:pointer"  onMouseUp=" RefreshImage()" />function RefreshImage()
    {
       var el =document.getElementById("unum1");
       el.src='include/randnum.php';//这个特别重要
    }
      

  4.   

    <img  src="include/randnum.php?mr=rand()" title="单击刷新" style="cursor:pointer"  onMouseUp=" RefreshImage()" /验证码图片获得的路劲需要加个随机数,不然图片访问的路径没变化,就访问的缓存去了