OpenCart - 如何在点击时重新加载验证码图像?

时间:2014-03-29 09:50:36

标签: php image opencart captcha reload

有很多关于如何在点击时重新加载验证码图像的例子,它们都有'captcha.php'作为图像源,例如。

<img id="captcha" src="captcha.php">

<a id='reload'>Refresh now</a>

$('#reload').click(function(){
    $('#captcha').attr('src','captcha.php')
})

我的表单中OpenCart中的图像源是

<img id="captcha_img" src="index.php?route=information/contact/securimage" alt="CAPTCHA Image" />

如果我这样做:

<script>
$(function() {
    $('#captcha_img').click(function(){ 
        $('img').attr('src', '<?php echo "index.php?route=information/contact/securimage" ?>?' + (new Date).getTime());
    });
});
</script>

加载第一张图片,但是当我点击图片时,新图片无法加载。看起来我没有指定正确的URL。我需要在OpenCart的脚本中设置什么路径?谢谢。

1 个答案:

答案 0 :(得分:4)

<script>
$(function() {
    $('#captcha_img').click(function(){ 
        $(this).attr('src', '<?php echo "index.php?route=information/contact/securimage" ?>&time=' + (new Date).getTime());
    });
});
</script>

这有效吗?