DWR util.js 学习笔记 整理

util.js包含一些有用的函数function,用于在客户端页面调用,它可以和dwr分开,独立营用于你的系统中。

主要功能如下:
1、$() 获得页面参数值
2、addOptions and removeAllOptions 初始化下拉框
3、addRows and removeAllRows  填充表格
4、getText  取得text属性值
5、getValue 取得form表单值
6、getValues 取得form多个值
7、onReturn  
8、selectRange
9、setValue
10、setValues
11、toDescriptiveString
12、useLoadingMessage
13、Submission box

***************************************************************************************
//////////////////////////////////////////////////////////////////////////////////////
****************************************************************************************
1、$()函数
  IE5.0 不支持
  $ = document.getElementById
  取得form表单值
  var name = $("name");
***************************************************************************************
//////////////////////////////////////////////////////////////////////////////////////
****************************************************************************************
2、用于填充 select 下拉框 option
  a、如果你想在更新select 时,想保存原来的数据,即在原来的select中添加新的option:
     var sel = DWRUtil.getValue(id);
     DWRUtil.removeAllOptions(id);
     DWRUtil.addOptions(id,...);
     DWRUtil.setValue(id,sel);
     demo:比如你想添加一个option:“--请选择--”
    DWRUtil.addOptions(id,["--请选择--"]);

DWRUtil.addOptions()有5中方式:

@ Simple Array Example: 简单数组
      例如:
      Array array = new Array[ 'Africa', 'America', 'Asia', 'Australasia', 'Europe' ];
      DWRUtil.addOptions("demo1",array);

@ Simple Object Array Example 简单数组,元素为beans
      这种情况下,你需要指定要显示 beans 的 property 以及 对应的 bean 值
      例如:
       public class Person {
     private String name;
     private Integer id;
     pirvate String address;
     public void set(){……}
     public String get(){……}
       }
       DWRUtil.addOptions("demo2",array,'id','name');
       其中id指向及bean的id属性,在optiong中对应value,name指向bean的name属性,对应下拉框中显示的哪个值.

@ Advanced Object Array Example 基本同上
    DWRUtil.addOptions( "demo3", 
                [{ name:'Africa', id:'AF' },
                 { name:'America', id:'AM' },
                 { name:'Asia', id:'AS' },
                 { name:'Australasia', id:'AU' },
                 { name:'Europe', id:'EU' }
        ],'id','name');

@ Map Example 用制定的map来填充 options:
       如果 server 返回 Map,呢么这样处理即可:
       DWRUtil.addOptions( "demo3",map);
       其中 value 对应 map keys,text 对应 map values;

@ <ul> and <ol> list editing

DWRUtil.addOptions() 函数不但可以填出select,开可以填出<ul>和<ol>这样的heml元素

***************************************************************************************
//////////////////////////////////////////////////////////////////////////////////////
****************************************************************************************
3、addRows and removeAllRows  填充表格
   DWR 提供2个函数来操作 table;
   ----------------------------
   DWRUtil.addRows(); 添加行
   ----------------------------
   DWRUtil.removeAllRows(id); 删除指定id的table
   ----------------------------
   下面着重看一下 addRows() 函数:

DWRUtil.addRows(id, array, cellfuncs, [options]);
    其中id 对应 table 的 id(更适合tbodye,推荐使用 tbodye)
    array 是server端服务器的返回值,比如list,map等等
    cellfuncs 及用返回值来天春表格
    [options] 用来设置表格样式,它有2个内部函数来设置单元格样式(rowCreator、cellCreator)。

比如: server端返回list,而list中存放的是下面这个 bean:
        public class Person {
     private String name;
     private Integer id;
     pirvate String address;
     public void set(){……}
     public String get(){……}
       }

下面用  DWRUtil.addRows(); 
   /**************************************************************************************/
   /****************** 胡国清***********fzfx88@hotmail.com********************************/
   /**************************************************************************************/

function userList(data){
    //var delButton = "<input type='button'/>";
    //var editButton = "<input type='button'/>";
    var cellfuncs = [
        function(data){return data.id;},
        function(data){return data.userName;},
        function(data){return data.userTrueName;},
        function(data){return data.birthday;},
        function(data){
            var idd = data.id;
            var delButton = document.createElement("<INPUT TYPE='button' onclick='delPerson("+ idd +")'>");
            delButton.setAttribute("id","delete");
            delButton.setAttribute("value","delete");
            return delButton;
        },
        function(data){
            var idd = data.id;
            var editButton = document.createElement("<INPUT TYPE='button' onclick='editPerson("+ idd +")'>");
            editButton.setAttribute("name","edit");
            editButton.setAttribute("value","edit");            
            return editButton;
        }
    ];
    DWRUtil.removeAllRows('tabId');    
    DWRUtil.addRows('tabId', data,cellfuncs,{
    rowCreator:function(options) {
        var row = document.createElement("tr");
        var index = options.rowIndex * 50;
        row.setAttribute("id",options.rowData.id);
        row.style.collapse = "separate";
        row.style.color = "rgb(" + index + ",0,0)";
        return row;
      },
      cellCreator:function(options) {
        var td = document.createElement("td");
        var index = 255 - (options.rowIndex * 50);
        //td.style.backgroundColor = "rgb(" + index + ",255,255)";
        td.style.backgroundColor = "menu";
        td.style.fontWeight = "bold";
        td.style.align = "center";
        return td;
      }        
    });
    document.getElementById("bt").style.display = "none";
     }
     待续…………………………………………
   /**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/
   4、getText  取得text属性值

DWRUtil.getText(id): 用来获得 option 中的文本
      比如:
       <select id="select">
    <option  value="1"> 苹果 </option>
    <option  value="2" select> 香蕉 </option>
    <option  value="3"> 鸭梨 </option>
       </select>
      调用 DWRUtil.getText("select"); 将返回 "香蕉" 字段;
      DWRUtil.getText(id);仅仅是用来获得 select 文本值,其他不适用。
   /**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/

5、DWRUtil.getValue(id): 用来获得 form 表单值

有如下几种情况:
          Text area (id="textarea"): DWRUtil.getValue("textarea")将返回 Text area的值;
      Selection list (id="select"): DWRUtil.getValue("select") 将返回 Selection list 的值;
      Text input (id="text"): DWRUtil.getValue("text") 将返回 Text input 的值;
      Password input (id="password"): DWRUtil.getValue("text") 将返回 Password input 的值;
      Form button (id="formbutton"): DWRUtil.getValue("formbutton") 将返回 Form button 的值;
      Fancy button (id="button"): DWRUtil.getValue("formbutton") 将返回 Fancy button 的值;
   /**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/

6、getValues 取得form多个值
      批量获得页面表单的值,组合成数组的形式,返回 name/value;

例如: form():
       <input type="textarea" id="textarea" value="1111"/>
       <input type="text" id="text" value="2222"/>
       <input type="password" id= "password" value="3333"/>
       <select id="select">
    <option  value="1"> 苹果 </option>
    <option  value="4444" select> 香蕉 </option>
    <option  value="3"> 鸭梨 </option>
       </select>
       <input type="button" id="button" value="5555"/>

那么: DWRUtil.getValues({textarea:null,select:null,text:null,password:null,button:null})
      将返回  ^^^^^^^^^^^^^^^^{textarea:1111,select:4444,text:2222,password:3333,button:5555}

/**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/

7、DWRUtil.onReturn 防止当在文本框中输入后,直接按回车就提交表单。

<input type="text" onkeypress="DWRUtil.onReturn(event, submitFunction)"/>
     <input type="button" onclick="submitFunction()"/>

/**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/

8、DWRUtil.selectRange(ele, start, end);

在一个input box里选一个范围

DWRUtil.selectRange("sel-test", $("start").value, $("end").value);

比如:<input type="text" id="sel-test" value="012345678901234567890">

DWRUtil.selectRange("sel-test", 2, 15); 结果 文本框中的值"2345678901234"将被选中'

/**************************************************************************************/
   /**************************************************************************************/
   /**************************************************************************************/

9、DWRUtil.setValue(id,value);
      为指定的id元素,设置一个新值;
   /**************************************************************************************/
   10、DWRUtil.setValues({  
    name: "fzfx88", 
    password: "1234567890" 
    }
       ); 同上,批量更新表单值.
   /**************************************************************************************/

11、DWRUtil.toDescriptiveString()

带debug信息的toString,第一个为将要debug的对象,第二个参数为处理等级。等级如下:

0: Single line of debug 单行调试  
    1: Multi-line debug that does not dig into child objects 不分析子元素的多行调试  
    2: Multi-line debug that digs into the 2nd layer of child objects 最多分析到第二层子元素的多行调试

<input type="text" id="text">
    DWRUtil。toDescriptiveString("text",0);
   /**************************************************************************************/

12、DWRUtil.useLoadingMessage();
    当发出ajax请求后,页面显示的提示等待信息;

function searchUser(){
    var loadinfo = "loading....."
    try{
        regUser.queryAllUser(userList);
        DWRUtil.useLoadingMessage(loadinfo);        
    }catch(e){

}
    }

/**************************************************************************************/

(0)

相关推荐

  • dwr spring的集成实现代码

    一,spring的正确使用 1,dwr.xml的配置 复制代码 代码如下: <dwr> <allow> <!-- dwr+spring --> <create creator="spring" javascript="JCustomerManager"> <param name="beanName" value="customerManager"/> </cre

  • 利用DWRCC突破天网防火墙(经验)(图)

    题外音:今天早上,为了逗BBS好友云舒开心,特告知她本人所用服务器之账户及口令,让她看看我的好东东.同时,我和她登录同一台开启3389肉机使用软件登录本人服务器,晕,吓的要死,还好,不是别人,*^_^* 系统环境: 采用windows 2000 professional做为本人所用局域网内网关,当前运行软件,天网4.2.8个人测试版,金山病毒防火墙,Sygate(以下简称服务器) 以下所有的图片都是在局域网内98机器上抓图,本人所用98+windows 2000远程终端服务连接器及其他相关软件(

  • AJAX实践DWR篇

    DWR(Direct Web Remoting)是一个WEB远程调用框架.利用这个框架可以让AJAX开发变得很简单.利用DWR可以在客户端利用JavaScript直接调用服务端的Java方法并返回值给JavaScript就好像直接本地客户端调用一样(DWR根据Java类来动态生成JavaScrip代码).它的最新版本DWR0.6添加许多特性如:支持Dom Trees的自动配置,支持Spring(JavaScript远程调用spring bean),更好浏览器支持,还支持一个可选的commons-

  • Dwr3.0纯注解(纯Java Code配置)配置与应用浅析一之零配置文件化

    //Annotation configuration dwr servletprivate void initializeDwrServlet(ServletContext container) {DwrServlet dwrServlet = new DwrServlet(); ServletRegistration.Dynamic dynamic = container.addServlet("dwr-invoker", dwrServlet ); dynamic.setLoadO

  • Dwr3.0纯注解(纯Java Code配置)配置与应用浅析二之前端调用后端

    首先当我们将Dwr3配置好以后,我们可以在浏览器中测试一下,查看一下我们配置的Dwr有没有生效,方法是 http://localhost:[你的服务器端口号,默认不写为80]/[ Web 名称 ]/dwr/,回车后就会出现你之前定义的Dwr的script的名称了,如下所显示这样: 当你点击第一个remote的时候会出现如下所示页面: 出现这样的页面就说明你的Dwr基本配置成功了,为什么说基本成功,因为这里面显示了你这个Service组件所有的方法,但是有一点就是,只有你注解了@RemoteMet

  • jsp dwr级联效果代码

    dwr.jsp <script src="dwr/interface/JUserChec.js"></script> <script src="dwr/engine.js"></script> <script src="dwr/util.js"></script> <script type="text/javascript"> function

  • Dwr3.0纯注解(纯Java Code配置)配置与应用浅析三之后端反向调用前端

    在前两篇中我们已经介绍了Dwr零配置文化化和前端调用后端的方法,想必大家应该已经会熟练掌握了,下来我们主要探讨一下后端怎么反向调用前端的js方法: 就如前两篇说到了用Dwr注册了两个Service组件,一个是remote,另外一个是页面使用到的controller,这个remote是在页面一加载进来就会被调用的,这样就使得会话和页面ScriptSession建立了绑定的关系,方便我们后面使用它的scriptSessionId进行页面定向推送: 下面是建立会话和页面ScriptSession的方法

  • DWR util.js 学习笔记 整理

    util.js包含一些有用的函数function,用于在客户端页面调用,它可以和dwr分开,独立营用于你的系统中. 主要功能如下: 1.$() 获得页面参数值 2.addOptions and removeAllOptions 初始化下拉框 3.addRows and removeAllRows  填充表格 4.getText  取得text属性值 5.getValue 取得form表单值 6.getValues 取得form多个值 7.onReturn   8.selectRange 9.se

  • DWR  util.js 学习笔记 整理

    util.js包含一些有用的函数function,用于在客户端页面调用,它可以和dwr分开,独立营用于你的系统中. 主要功能如下: 1.$() 获得页面参数值 2.addOptions and removeAllOptions 初始化下拉框 3.addRows and removeAllRows  填充表格 4.getText  取得text属性值 5.getValue 取得form表单值 6.getValues 取得form多个值 7.onReturn   8.selectRange 9.se

  • Java中jqGrid 学习笔记整理——进阶篇(二)

    相关阅读: Java中jqGrid 学习笔记整理--进阶篇(一) 本篇开始正式与后台(java语言)进行数据交互,使用的平台为 JDK:java 1.8.0_71 myEclisp 2015 Stable 2.0 Apache Tomcat-8.0.30 Mysql 5.7 Navicat for mysql 11.2.5(mysql数据库管理工具) 一.数据库部分 1.创建数据库 使用Navicat for mysql创建数据库(使用其他工具或直接使用命令行暂不介绍) 2. 2.创建表 双击打

  • jqGrid 学习笔记整理——进阶篇(一 )

    在浏览导航栏添加所需按钮 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>DEMO</title> <link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css" /> <link rel=&

  • JavaScript学习笔记整理_setTimeout的应用

    setTimeou的t应用 var ids = []; function foo1(i) { this.i = i; console.log('i = '+i); ids[0] = setTimeout((function () { foo1(i); }),1000); } function foo2(j) { this.j = j; console.log('j = '+j); ids[1] = setTimeout((function () { foo2(j); }),1000); } fo

  • Python学习笔记整理3之输入输出、python eval函数

    1. python中的变量: python中的变量声明不需要像C++.Java那样指定变量数据类型(int.float等),因为python会自动地根据赋给变量的值确定其类型.如 radius = 20,area = radius * radius * 3.14159 ,python会自动的将radius看成"整型",area看成"浮点型".所以编程时不用再像之前那样小心翼翼的查看数据类型有没有出错,挺人性化的. 2. input和print: 先贴个小的程序 #

  • C#学习笔记整理_浅谈Math类的方法

    c#中Math类的方法 Math.Abs 已重载. 返回指定数字的绝对值. Math.Acos 返回余弦值为指定数字的角度. Math.Asin 返回正弦值为指定数字的角度. Math.Atan 返回正切值为指定数字的角度. Math.Atan2 返回正切值为两个指定数字的商的角度. Math.BigMul 生成两个 32 位数字的完整乘积. Math.Ceiling 已重载. 返回大于或等于指定数字的最小整数. Math.Cos 返回指定角度的余弦值. Math.Cosh 返回指定角度的双曲余

  • JavaScript学习笔记整理_关于表达式和语句

    表达式和语句 eval( ) 只有一个参数 参数非字符串时,直接返回这个参数: 参数为字符串时,它把字符串当成JavaScript代码进行编译,编译失败则抛出语法错误,编译成功则执行代码,并返回最后一条语句的值,若没有值则返回undefined eval()使用了调用它的变量的作用域环境 它接收的字符串参数,在作为单独的代码时,必须是有语义的,否则编译失败 delete运算符:用来删除对象的自由属性.数组的元素, 删除属性后,属性将不存在,而删除数组元素后,会在数组内留下一个值为undefine

  • JavaScript学习笔记整理_简单实现枚举类型,扑克牌应用

    如下所示: //实现枚举类型,扑克牌应用 function creatEnum(p){ //构造函数 var Enumeration = function(){throw 'can not Instantiate Enumerations';}; //重写原型并将原型赋值给变量proto var proto = Enumeration.prototype = { constructor:Enumeration, toString:function(){return this.name;}, va

  • vue.js学习笔记之绑定style样式和class列表

    数据绑定一个常见需求是操作元素的 class 列表和它的内联样式.因为它们都是 attribute,我们可以用 v-bind 处理它们:只需要计算出表达式最终的字符串.不过,字符串拼接麻烦又易错.因此,在 v-bind 用于 class 和 style 时,Vue.js 专门增强了它.表达式的结果类型除了字符串之外,还可以是对象或数组. 一.绑定Class属性. 绑定数据用v-bind:命令,简写成: 语法:<div v-bind:class="{ active: isActive }&q

随机推荐