【问题标题】:Refreshing a particular div with reloading the whole page in php通过在 php 中重新加载整个页面来刷新特定的 div
【发布时间】:2017-06-08 09:34:49
【问题描述】:

我需要重新加载特定的 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>

一旦我点击刷新验证码文本框应该会被清除。

【问题讨论】:

  • 对您的服务器端 php 方法执行 ajax 调用..
  • 实际上我尝试了一些代码但没有工作
  • 能否请您展示一下您的尝试?
  • 如果我在 div 中输入验证码文本并刷新验证码,那么 div 应该会被清除
  • 你尝试了什么。你应该发布你的 ajax 代码

标签: javascript jquery html css codeigniter


【解决方案1】:

$('.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>

【讨论】:

    【解决方案2】:

    试试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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 2013-02-22
      • 1970-01-01
      • 2016-04-23
      • 2013-08-22
      相关资源
      最近更新 更多