Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2561853
  • 博文数量: 245
  • 博客积分: 4125
  • 博客等级: 上校
  • 技术积分: 3113
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-25 23:56
文章分类

全部博文(245)

文章存档

2015年(2)

2014年(26)

2013年(41)

2012年(40)

2011年(134)

2010年(2)

分类: JavaScript

2013-05-23 12:15:49

效果:

直接上代码,例子中extjs是使用的在线的,需要引入kindeditor即可运行:

点击(此处)折叠或打开

  1. <html>
  2. <head>
  3. <title>Account Manager</title>
  4. <meta charset="utf-8" />
  5. <link rel="stylesheet" href="../kindeditor/themes/default/default.css" />
  6. <link rel="stylesheet" href="../kindeditor/plugins/code/prettify.css" />
  7. <script charset="utf-8" src="../kindeditor/kindeditor.js"></script>
  8. <script charset="utf-8" src="../kindeditor/lang/zh_CN.js"></script>
  9. <script charset="utf-8" src="../kindeditor/plugins/code/prettify.js"></script>

  10. <link rel="stylesheet" type="text/css"
  11.     href="">

  12. <script type="text/javascript"
  13.     src=""></script>
  14. <script type="text/javascript"
  15.     src=""></script>


  16. <script type="text/javascript">
  17.     Ext.require([ 'Ext.form.*', 'Ext.tip.*' ]);

  18.     Ext
  19.             .onReady(function() {

  20.                 Ext
  21.                         .apply(
  22.                                 Ext.form.field.VTypes,
  23.                                 {
  24.                                     password : function(val, field) {
  25.                                         if (/^[a-z0-9]+$/i.test(val)) {
  26.                                             return true;
  27.                                         }
  28.                                     },
  29.                                     passwordText : 'Password may only contain letters and numbers.'
  30.                                 });

  31.                 Ext.QuickTips.init();

  32.                 function submitOnEnter(field, event) {
  33.                     if (event.getKey() == event.ENTER) {
  34.                         var form = field.up('form').getForm();
  35.                         form.submit();
  36.                     }
  37.                 }

  38.                 function password(length, special) {
  39.                     var iteration = 0;
  40.                     var password = '';
  41.                     var randomNumber;

  42.                     if (special == undefined) {
  43.                         var special = false;
  44.                     }

  45.                     while (iteration < length) {
  46.                         randomNumber = (Math.floor((Math.random() * 100)) % 94) + 33;
  47.                         if (!special) {
  48.                             if ((randomNumber >= 33) && (randomNumber <= 47)) {
  49.                                 continue;
  50.                             }
  51.                             if ((randomNumber >= 58) && (randomNumber <= 64)) {
  52.                                 continue;
  53.                             }
  54.                             if ((randomNumber >= 91) && (randomNumber <= 96)) {
  55.                                 continue;
  56.                             }
  57.                             if ((randomNumber >= 123) && (randomNumber <= 126)) {
  58.                                 continue;
  59.                             }
  60.                         }
  61.                         iteration++;
  62.                         password += String.fromCharCode(randomNumber);
  63.                     }
  64.                     return password;
  65.                 }

  66.                 /**
  67.                  * 信息内容
  68.                  */
  69.                 var content = new Ext.form.TextArea(
  70.                         {
  71.                             fieldLabel : '信息内容',
  72.                             maxLength : '1000',
  73.                             height : 150,
  74.                             maxLengthText : '文章提示信息长度不能超过2000字',
  75.                             name : 'content',
  76.                             id : 'content',
  77.                             emptyText : '无',
  78.                             anchor : '80%',
  79.                             listeners : {
  80.                                 "render" : function(f) {
  81.                                     K = KindEditor;
  82.                                     htmlEditor = K
  83.                                             .create(
  84.                                                     '#content',
  85.                                                     {
  86.                                                         uploadJson : '../kindeditor/jsp/upload_json.jsp',//路径自己改一下
  87.                                                         fileManagerJson : '../kindeditor/jsp/file_manager_json.jsp',//路径自己改一下
  88.                                                         height : 200,
  89.                                                         width : '90%',
  90.                                                         // fontSizeTable:['21px','20px','17px','18px','16px','14px','12px'],
  91.                                                         resizeType : 1,
  92.                                                         allowPreviewEmoticons : true,
  93.                                                         allowImageUpload : true
  94.                                                     });
  95.                                 }
  96.                             }
  97.                         });

  98.                 // Form
  99.                 // -----------------------------------------------------------------------
  100.                 var addUserForm = Ext.create('Ext.form.Panel', {
  101.                     renderTo : Ext.getBody(),
  102.                     bodyStyle : 'padding: 5px 5px 0 5px;',
  103.                     defaults : {
  104.                         xtype : 'textfield',
  105.                         anchor : '100%',
  106.                     },
  107.                     items : [ {
  108.                         fieldLabel : 'Email',
  109.                         name : 'email',
  110.                         vtype : 'email',
  111.                         maxLength : 64,
  112.                         allowBlank : false,
  113.                         listeners : {
  114.                             specialkey : submitOnEnter
  115.                         }
  116.                     }, {
  117.                         xtype : 'fieldcontainer',
  118.                         fieldLabel : 'Password',
  119.                         layout : 'hbox',
  120.                         items : [ {
  121.                             xtype : 'textfield',
  122.                             name : 'password',
  123.                             flex : 1,
  124.                             vtype : 'password',
  125.                             minLength : 4,
  126.                             maxLength : 32,
  127.                             allowBlank : false,
  128.                             listeners : {
  129.                                 specialkey : submitOnEnter
  130.                             }
  131.                         }, {
  132.                             xtype : 'button',
  133.                             text : 'Random',
  134.                             tooltip : 'Generate a random password',
  135.                             style : 'margin-left: 4px;',
  136.                             flex : 0,
  137.                             handler : function() {
  138.                                 this.prev().setValue(password(8, false));
  139.                                 this.prev().focus()
  140.                             }
  141.                         } ]
  142.                     }, content ],
  143.                     buttons : [ {
  144.                         id : 'saveBtn',
  145.                         itemId : 'saveBtn',
  146.                         text : 'Submit',
  147.                         handler : function() {
  148.                             this.up('form').getForm().submit();
  149.                         }
  150.                     }, {
  151.                         text : 'Cancel',
  152.                         handler : function() {
  153.                             this.up('form').getForm().reset();
  154.                         }
  155.                     } ],
  156.                     submit : function() {
  157.                         var currentForm = this.owner.form;

  158.                         if (currentForm.isValid()) {
  159.                             // var newSomething = Ext.create('Something', currentForm.getFieldValues());
  160.                         }
  161.                     }
  162.                 });
  163.             });
  164. </script>
  165. </head>
  166. <body></body>
  167. </html>


阅读(4745) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~