1

我在 extjs 工作。我想以 extjs 形式生成验证码。所以我正在使用具有代码的javascript创建验证码 -

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
     <title>BotBoot</title>

         <script type="text/javascript">
         var a = Math.ceil(Math.random() * 10);
         var b = Math.ceil(Math.random() * 10);       
         var c = a + b
         function DrawBotBoot()
        {
         document.write("What is "+ a + " + " + b +"? ");
         document.write("<input id='BotBootInput' type='text' maxlength='2'    size='2'/>");
        }    
        function ValidBotBoot(){
        var d = document.getElementById('BotBootInput').value;
        if (d == c) return true;        
        return false;

     }
     </script>

     </head>
     <body>

      Are you human?<br />

       <script type="text/javascript">DrawBotBoot()</script>
       <input id="Button1" type="button" value="Check"  onclick="alert(ValidBotBoot());"/>

      </body>
      </html>

它工作正常。但是现在我想通过提及 xtype 字段在我的注册表单中包含这个 javascript 验证码在项目块内。那么如何在 extjs 视图表单项元素中包含 javascript?

4

1 回答 1

1

您需要创建一个文本字段和一个按钮以及一个看起来像这样的自定义类。如果你实现它,你可以使用它xtype: 'captcha'

Ext.define('My.Captcha', {
    extend: 'Ext.container.Container',
    alias: 'widget.captcha',

    initComponent: function(config){
        this.a = Math.ceil(Math.random() * 10);
        this.b = Math.ceil(Math.random() * 10);       
        this.c = this.a + this.b;
    },

    DrawBotBoot: function(){
      //custom logic
    },

    ValidBotBoot: function(){
      //custom logic
    }
});

如果您要在输入中使用 id,您可以使用它Ext.getCmp()来检索组件。
祝你好运

于 2013-01-09T07:39:09.743 回答