刷新验证码图像


Refresh Captcha Image

如何获取验证码图片的图片源来刷新验证码?

我正在尝试这样做,但它不起作用:

 <img id="captcha_img" src="<?php echo  CAPTCHA_PLUGIN_URL . "/captcha_images.php?width=120&height=40&code=$code?>"?>" />

Can't read the image? click <a href='javascript: refresh_captcha();'>here</a> to refresh
<script type="text/javascript">
var refr_no = 0;
function refresh_captcha()
{
   var im = new Image();
   refr_no = refr_no + 1;
   im.src = "<?php echo  CAPTCHA_PLUGIN_URL . "/captcha_images.php?width=120&height=40"?>&refresh=" + refr_no;
   document.getElementById ("captcha_img").src = im.src;
}
</script>

不需要创建图像对象。

function refresh_captcha()
{
   im = document.getElementById('captcha_img');
   refr_no = refr_no + 1;
   im.src = "<?php echo  CAPTCHA_PLUGIN_URL . "/captcha_images.php?width=120&height=40"?>&refresh=" + refr_no;
}

查看此演示:http://jsbin.com/ayenOce/2/edit

尝试:

<script type="text/javascript">
var refr_no = 0;
function refresh_captcha()
{
   refr_no = refr_no + 1;
   var oldSrc = document.getElementById("captcha_img").replace('&refresh='+(refr_no-1)+'','')+"&refresh="+refr_no;
   document.getElementById ("captcha_img").src = oldSrc;
   refr_no++;
}
</script>
<img id="captcha_img" src="<?php echo  CAPTCHA_PLUGIN_URL . "/captcha_images.php?width=120&height=40&code=$code?>"?>" />

Can't read the image? click <a href='#' onclick="refresh_captcha(); return false;">here</a> to refresh