• JQuery对象函数


    1、JQuery对象函数写法格式

    简单示例:

    main代表对象名,main.roleName = (function () { return $('#RoleName').val();})();表示为对象的roleName属性赋值。

     1 $(document).ready(function () {
     2 MainManager.init();
     3 });
     4 
     5 var MainManager = window.MainManager = {};
     6 
     7 (function (main) {
     8 main.init = function () {
     9 this.roleName();
    10 }
    11 
    12 main.roleName = (function () {
    13 return $('#RoleName').val();
    14 })();
    15 
    16 })(MainManager);

     实例:

    注意下面下拉列表写法格式,有多种情况可以借鉴,

      1 $(document).ready(function () {
      2     MainManager.init();
      3 });
      4 
      5 var MainManager = window.MainManager = {};
      6 
      7 
      8 (function (main) {
      9     main.init = function () {
     10         this.bindBtnSearch();
     11         this.bindBtnClear();
     12         this.initSearchCombo();
     13         this.initGirdMain();
     14     }
     15 
     16   
     17 
     18     main.roleName = (function () {
     19         return $('#RoleName').val();
     20     })();
     21 
     22     main.commType = (function () {
     23         return $('#frmSearch #CommType').val();
     24     })();
     25 
     26 
     27     main.initSearchCombo = function () {
     28         var frmSearch = $('#frmSearch');
     29         frmSearch.find('#Fstatus').first().combobox({
     30             valueField: 'CodeNO',
     31             textField: 'CodeName',
     32             panelHeight: 'auto',
     33             data: [
     34              { CodeNO: '', CodeName: '--全部--' },
     35              { CodeNO: 3, CodeName: '已保存' },
     36              { CodeNO: 0, CodeName: '待审核' },
     37              { CodeNO: 1, CodeName: '已审核' },
     38              { CodeNO: 2, CodeName: '已关闭' }
     39             ]
     40         });
     41 
     42         //下拉列表
     43         frmSearch.find('#FranchiseeNO').first().combotree({
     44             panelWidth: 330,
     45             panelHeight: 230,
     46             valueField: 'id',
     47             textField: 'text',
     48             url: '/v_JM_Franchisee/GetFranchiseeListData',
     49             onLoadSuccess: function (node, data) {
     50                 var rowCount = data.length;
     51                 if (rowCount > 0) {
     52                     $('#frmSearch #FranchiseeNO').combotree("setValue", data[0].id);
     53                 }
     54                 if ((data.length === 1) && (data[0].children == null)) {
     55                     $('#frmSearch #FranchiseeNO').combotree('disable');
     56                 };
     57             },
     58             method: 'post',
     59             editable: true
     60         });
     61 
     62         frmSearch.find('#CityID').first().combobox({
     63             url: '/area/getCitiesEnable',
     64             valueField: 'RegionID',
     65             textField: 'Name'
     66         });
     67 
     68         $("#frmSearch #DeptID").combotree({
     69             panelWidth: '230',
     70             panelHeight: '390',
     71             valueField: 'id',
     72             textField: 'text',
     73             url: '/SYS_Department/GetAllSYS_DepartmentByTree?_=' + (new Date()).valueOf(),
     74             editable: false
     75         });
     76     }
     77 
     78     //绑定查询按钮
     79     main.bindBtnSearch = function () {
     80         $('#frmSearch #btnSearch').bind('click', function () {
     81             if (!$("#frmSearch").form('validate')) return;
     82             main.queryGridMain(form2Json("frmSearch"));
     83         });
     84     }
     85 
     86     //绑定清空按钮
     87     main.bindBtnClear = function () {
     88         $('#frmSearch #btnClear').first().bind('click', function () {
     89             var frmSearch = $('#frmSearch');
     90             frmSearch.form('clear');
     91 
     92             var $franchiseeno = $('#frmSearch #FranchiseeNO');
     93             var $tree = $franchiseeno.combotree('tree');  // 获取数据表格对象
     94             var root = $tree.tree("getRoot");
     95             $franchiseeno.combotree('setValue', root.id);
     96            
     97             $("#frmSearch #Fstatus").combobox("setValue", "");
     98 
     99             frmSearch.find('#btnSearch').first().trigger('click');
    100         });
    101     }
    102 
    103     
    104     main.initGirdMain = function () {
    105         var config = Util.getBasicConfig();
    106         var queryModel = form2Json("frmSearch");
    107         $.extend(config, {
    108             url: '/ReceiveContract/ReceiveContract/GetAllReceiveContract',
    109             queryParams: queryModel,
    110             sortName: "CreateDate",
    111             sortOrder: "desc",
    112             onDblClickRow: function (rowIndex, rowData) {
    113                 MainManager.editContract();
    114             },
    115             columns: [
    116               [
    117                   {
    118                       field: "Fstatus", title: "审核状态",  80, align: "center", sortable: true,
    119                       formatter: function (value, rows) {
    120                           switch (value) {
    121                               case 2:
    122                                   return "<strong style='color:darkgray;'>已关闭</strong>";
    123                               case 0:
    124                                   return "<strong style='color:rosybrown;'>未审核</strong>";
    125                               case 1:
    126                                   return "<strong style='color:green;'>已审核</strong>";
    127                               case 3:
    128                                   return "<strong style='color:red;'>已保存</strong>";
    129                               default:
    130                                   return "--";
    131                           }
    132                       }
    133                   },
    134 
    135                   { field: "FContractNo", title: "编号",  90, align: "center", sortable: true }
    136 
    137               ]
    138             ]
    139         });
    140         var toolList = [
    141                 {
    142                     id: 'btnAdd', text: '添加', iconCls: 'icon-add',
    143                     handler: function () { MainManager.addContract(); }
    144                 }
    145         ];
    146         config.toolbar = toolList;
    147 
    148         $('#gridMain').datagrid(config);
    149     }
    150 
    151 
    152     //新增
    153     main.addContract = function () {
    154         $('#winEdit').window({
    155             height: Math.min($(window).height() * 0.9, 820),
    156             onLoad: function () {
    157                 EditManager.initAdd();
    158             },
    159             onClose: function () {
    160                 delete EditManager;
    161             },
    162             title: '新增',
    163             iconCls: 'icon-add'
    164         });
    165         $('#winEdit').window('center');
    166         $('#winEdit').window('open');
    167         $('#winEdit').window('refresh', '/ReceiveContract/ReceiveContract/EditContract?_=' + (new Date()).valueOf());
    168     }
    169 })(MainManager);
  • 相关阅读:
    一个IBM人的离职泪:伟大公司 SB老板 苦逼员工
    分享:cmake for protobuff
    鸽巢原理
    分享:ADT在线安装(http://dlssl.google.com/android/eclips...
    科学家将蝌蚪眼睛植入其尾部 并具有正常视力
    Artificial Intelligence: How To Build A Robot Udacity
    http://ndevilla.free.fr/
    发现几个计算广告学的课程
    base64_百度百科
    分享:查询日志过去一分钟的并发python
  • 原文地址:https://www.cnblogs.com/MirZhai/p/10057120.html
Copyright © 2020-2023  润新知