我需要在不重新加载整个页面的情况下重新加载特定的div。
<div class="">
<div class="contactpagecaptchas">
<img src="/captcha.php?rand=<?php echo rand();?>" class="contactpagecaptchass" id='captchaimg'/>
<p class="change"><a href="javascript: refreshCaptcha();" class="clickto">Click to change</a></p>
</div>
<div class="contactcaptcha">
<input type="text" class="form-control" name="captcha" placeholder="Captcha" style="background-color: #f4f4f4;border: none;">
</div>
</div>
一旦我点击刷新验证码,文本框就会被清除。
答案 0 :(得分:2)
$('.clickto').click(function() {
$('[name="captcha"]').val('');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="">
<div class="contactpagecaptchas">
<img src="/captcha.php?rand=<?php echo rand();?>" class="contactpagecaptchass" id='captchaimg' />
<p class="change"><a href="#" class="clickto">Click to change</a></p>
</div>
<div class="contactcaptcha">
<input type="text" class="form-control" name="captcha" placeholder="Captcha" style="background-color: #f4f4f4;border: none;">
</div>
</div>
答案 1 :(得分:0)
尝试使用javascript的onclick方法
<div id="abc" ><?php echo rand(); ?></div>
<button onclick="refcaptcha()" >
<script>
function refcaptcha(){
var x = document.getElementById("abc")
x.innerHTML = Math.floor((Math.random() * 1000000) + 1);
//if you want to clear the captcha code than assign '' to that id
//x.innerHTML = '';
}
</script>