日期:2014-05-16  浏览次数:20626 次

jquery写验证码的显示问题
显示出来的jquery代码不会写了 求各路神仙指定!!$(this).atter("src",$(this).html(data));
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#checkcode").click(function(){
$.post("checkcode.php",{aa:Math.random()},function(data){
$(this).atter("src",$(this).html(data));
})
 
});


});

</script>
</head>
<body>

请输入验证码:<input type="text" id="code"/><img src="checkcode.php" id="checkcode" />
</body>
</html>
下面是生成的验证码 checkcode.php
 <?php
  //
$checkCode="";
for($i=0;$i<4;$i++){
$checkCode.=dechex(rand(1,15));//转成功16进制
}


//存入到session中
session_start();
$_SESSION["checkCode"]=$checkCode;

// //1画布
$image1=imagecreatetruecolor(80,30);
  //画出干扰线
  for($i=0;$i<20;$i++){
  imageline($image1,rand(0,80),rand(0,30),rand(0,80),rand(0,30),imagecolorallocate($image1,rand(0,255),rand(0,255),rand(0,255)));
  }

  $red=imagecolorallocate($image1,255,255,255);
  imagestring($image1,rand(1,5),rand(0,45),rand(0,10),$checkCode,$red);
  header("content-type:image/png");
  imagepng($image1); 
  //销毁该图片(释放内存)
  imagedestory($image1);
?>

------解决方案--------------------
$("#checkcode").click(function() {
$(this).attr("src", "checkcode.php?"+Math.random());
});

上面少写了一个)