【问题标题】:clear inputbox onclick image清除输入框 onclick 图像
【发布时间】:2012-04-03 21:52:17
【问题描述】:

此行更新验证码图像,它也应该清除输入框“验证码”。

    <div id="refresh_button"><a href="#" onclick="refreshimg();return false;"><img src="refresh.gif"/></a></div>

    <input type="text" maxlength="6" name="captcha" id="captcha" class="captcha_inputbox" />

所以我必须修改onClick,但我找不到这个,即使用google也找不到。

非常感谢您的帮助

【问题讨论】:

    标签: javascript onclick inputbox


    【解决方案1】:

    您可以使用以下命令清除文本框的值:

    document.getElementById('captcha').value = '';
    

    或者,如果您使用的是 jQuery:

    $('#captcha').val('');
    

    【讨论】:

      【解决方案2】:

      最好在脚本标签中执行此操作。例如,您可以执行以下操作:

      <script type='text/javascript'>
         function refreshimg() {
            // do the refreshing here
      
            // since your input text has an id of 'captcha'
            document.getElementById("captcha").value = "";
      
            return false;
         }
      </script>
      

      然后在你的 HTML 中,你会这样做

      <div id="refresh_button"><a href="#" onclick="return refreshimg();"><img src="refresh.gif"/></a></div>
      <input type="text" maxlength="6" name="captcha" id="captcha" class="captcha_inputbox" />
      

      【讨论】:

        猜你喜欢
        • 2021-09-27
        • 2017-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-21
        • 1970-01-01
        • 2016-10-16
        • 2012-03-16
        相关资源
        最近更新 更多