zoukankan      html  css  js  c++  java
  • rails_ajax 验证验证码

    rails_ajax 验证验证码

    view

        <div class="form-group ">
                <%= rucaptcha_input_tag( class:'captcha-text',placeholder: '输入验证码') %>
                <%= rucaptcha_image_tag(class:'image-box', alt: 'Captcha') %>
                <%= image_tag("wrong.png",class:'wrong')%>
          </div>
    

    css 验证码输入错误时,显示出错误的图片(默认不显示)

    <style type="text/css">
        .wrong{
             22px;
            height: 22px;
            margin-left: -160px;
            display: none;
        }
    </style>>
    

    JS

    <script type="text/javascript">
        function change_captcha(){
            var src=$(".image-box").attr("src");
            $(".image-box").attr("src",src.split("?")[0]+"?"+(new Date().getTime()))
        }
        $(".image-box").click(function(){
            change_captcha();
            $(".wrong").hide();
            $(".captcha-text").attr(value,"");
        })
       // 监听文本框字数变化
        $(".captcha-text").on('keyup', function(event) {
            var content=$(".captcha-text").val();
            var length=content.length
            // 验证码为4位
            if (length==4){
             $.ajax({
              type:"GET",
              url:"/users/verify_rucaptcha",//验证验证码的action
              //使用rucaptcha插件时,传送验证的params的名称是_rucaptcha
               data: {_rucaptcha: content}
               success:function(result){
                  if(result=="false")
                  {
                    //验证码错误时,显示错误提示
                    $(".wrong").show();
                }
                return ;
            }
        })
         }
     });
    
    </script>
    

    controller

     def verify_rucaptcha
        if verify_rucaptcha?(params[:_rucaptcha])
          # 不渲染视图,只返回信息
          render  plain: "true"
        else 
          render  plain: "false"
        end
      end
    
  • 相关阅读:
    jvm类加载机制
    线程误区-join,wait(里边还是调用的wait)
    线程间通信wait和notify【All】简介
    指令重排序
    window.opener
    scrollIntoView()
    保持饥饿,保持愚蠢
    执行sql语句,不依靠实体 获取string值
    join函数详解
    html常用代码大全
  • 原文地址:https://www.cnblogs.com/dccmmtop/p/7513289.html
Copyright © 2011-2022 走看看