version 2.0 通用js小功能
form表单处理
Example block-level help text here.
-- 请选择 --
  • -- 请选择 --
  • basketball
  • volleyball
  • badminton
重置 保存
监听键盘事件
                            $(document).keydown(function(){
                                var keyCode = doKeycode();
                                if(keyCode == 38){
                                    //do something...
                                }
                            });
                        
监听鼠标位置
                            $(document).on('mousemove', function () {
                                var position = mouseMove();
                                if (position.x > 520 && position.y < 520) {
                                    //do something...
                                }
                            });
                        
数组操作
                            var arr = [1, 34, 54, 3, 4, 2, 5];
                            arr.maxArr();   //数组求最大值:54
                            arr.minArr();   //数组求最小值:1
                            arr.sumArr();   //数组求和:103
                            arr.averageArr();   //数组求平均值:14.714285714285714
                        
数组排序
                            var arr = [1, 34, 54, 3, 4, 2, 5];
                            arr.sort($.sortAsc);    //数组升序:1,2,3,4,5,34,54
                            arr.sort($.sortDesc);   //数组降序:54,34,5,4,3,2,1
                        
数组对象排序
                            var arrObjA = [
                                {"name": "建筑安装业", "value": 123},
                                {"name": "科技推广和应用服务业", "value": 66},
                                {"name": "专用设备制造业", "value": 41},
                                {"name": "汽车制造业", "value": 37},
                                {"name": "研究和试验发展服务业", "value": 7},
                                {"name": "房地产业", "value": 102},
                                {"name": "商务服务业", "value": 237},
                                {"name": "保险业", "value": 63},
                                {"name": "通用设备制造业", "value": 166},
                                {"name": "医药制造业", "value": 72}
                            ];
                            arrObjA.sort($.sortByAttrAsc('value'));
                            /*排序结果:数组对象升序:根据参数value排序
                             * [{name: "研究和试验发展服务业", value: 7},
                             * {name: "汽车制造业", value: 37},
                             * {name: "专用设备制造业", value: 41},
                             * {name: "保险业", value: 63},
                             * {name: "科技推广和应用服务业", value: 66},
                             * {name: "医药制造业", value: 72},
                             * {name: "房地产业", value: 102},
                             * {name: "建筑安装业", value: 123},
                             * {name: "通用设备制造业", value: 166},
                             * {name: "商务服务业", value: 237}]
                             */

                            arrObjA.sort($.sortByAttrDesc('value'));   //数组对象降序
                        
序列化form内容
                            var userInfo = $('#userInfoForm').serializeJson();//jquery对象操作的是form的ID
                        
反序列化form内容
                            $('#userInfoForm').deserializeForm(formData);//formData为json数据