DWR util.js 整理(DWR 处理各种form表单Select/option,table等,

DWR util.js 学习笔记
/********************/

/********************/
util.js包含一些有用的函数function,用于在客户端页面调用.
主要功能如下:

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

 

*********************************************************************
//http://blog.163.com/fzfx888//
*********************************************************************

代码
  1. 1、$()函数   
  2.      IE5.0 不支持   
  3.      $ = document.getElementById   
  4.      取得form表单值   
  5.      var name = $("name");  


***********************************************************************************
///
***********************************************************************************
2、用于填充 select 下拉框 option

代码
  1. a、如果你想在更新select 时,想保存原来的数据,即在原来的select中添加新的option:   
  2.        var sel = DWRUtil.getValue(id);   
  3.        DWRUtil.removeAllOptions(id);   
  4.        DWRUtil.addOptions(id,...);   
  5.        DWRUtil.setValue(id,sel);   
  6.        demo:比如你想添加一个option:“--请选择--”   
  7. DWRUtil.addOptions(id,["--请选择--"]);    
  8.   
  9.       DWRUtil.addOptions()有5中方式:  

 

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

 

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

 

代码
  1. @ Advanced Object Array Example 基本同上   
  2.        DWRUtil.addOptions( "demo3",    
  3.                    [{ name:'Africa', id:'AF' },   
  4.                     { name:'America', id:'AM' },   
  5.                     { name:'Asia', id:'AS' },   
  6.                     { name:'Australasia', id:'AU' },   
  7.                     { name:'Europe', id:'EU' }   
  8.            ],'id','name');  

 

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

 

代码
  1. @ <ul> and <ol> list editing   
  2.         
  3.           DWRUtil.addOptions() 函数不但可以填出select,开可以填出<ul>和<ol>这样的heml元素  


***********************************************************************************
///fzfx88@163.com//
***********************************************************************************
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:

代码
  1.       public class Person {   
  2. private String name;   
  3. private Integer id;   
  4. pirvate String address;   
  5. public void set(){……}   
  6. public String get(){……}   
  7.         }  


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

 

 

代码
  1.       function userList(data){   
  2.     //var delButton = "<input type='button'/>";   
  3.     //var editButton = "<input type='button'/>";   
  4.        var cellfuncs = [   
  5.            function(data){return data.id;},   
  6.            function(data){return data.userName;},   
  7.            function(data){return data.userTrueName;},   
  8.            function(data){return data.birthday;},   
  9.            function(data){   
  10.            var idd = data.id;   
  11. var delButton = document.createElement("<INPUT TYPE='button' οnclick='delPerson("+ idd +")'>");   
  12.                delButton.setAttribute("id","delete");   
  13.                delButton.setAttribute("value","delete");   
  14.             return delButton;   
  15.            },   
  16.            function(data){   
  17.                var idd = data.id;   
  18.                var editButton = document.createElement("<INPUT TYPE='button' οnclick='editPerson("+ idd +")'>");   
  19.                editButton.setAttribute("name","edit");   
  20.                editButton.setAttribute("value","edit");               
  21.             return editButton;   
  22.            }   
  23.        ];   
  24.        DWRUtil.removeAllRows('tabId');    
  25.        DWRUtil.addRows('tabId', data,cellfuncs,{   
  26.        rowCreator:function(options) {   
  27.            var row = document.createElement("tr");   
  28.            var index = options.rowIndex * 50;   
  29.            row.setAttribute("id",options.rowData.id);   
  30.            row.style.collapse = "separate";   
  31.            row.style.color = "rgb(" + index + ",0,0)";   
  32.         return row;   
  33.        },   
  34.        cellCreator:function(options) {   
  35.            var td = document.createElement("td");   
  36.            var index = 255 - (options.rowIndex * 50);   
  37.         //td.style.backgroundColor = "rgb(" + index + ",255,255)";   
  38.            td.style.backgroundColor = "menu";   
  39.            td.style.fontWeight = "bold";   
  40.            td.style.align = "center";   
  41.         return td;   
  42.        }          
  43.        });   
  44.        document.getElementById("bt").style.display = "none";   
  45.         }  


待续…………………………………………
/********************************************************************************/
/***********************QQ: 171505924 Gump **************************************/
/********************************************************************************/
4、getText 取得text属性值

DWRUtil.getText(id): 用来获得 option 中的文本
比如:

代码
  1.       <select id="select">  
  2. <option  value="1"> 苹果 </option>  
  3. <option  value="2" select> 香蕉 </option>  
  4. <option  value="3"> 鸭梨 </option>  
  5.       </select>  


调用 DWRUtil.getText("select"); 将返回 "香蕉" 字段;
DWRUtil.getText(id);仅仅是用来获得 select 文本值,其他不适用。
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/

 

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

有如下几种情况:

代码
  1.           Text area (id="textarea"): DWRUtil.getValue("textarea")将返回 Text area的值;   
  2. Selection list (id="select"): DWRUtil.getValue("select") 将返回 Selection list 的值;   
  3. Text input (id="text"): DWRUtil.getValue("text") 将返回 Text input 的值;   
  4. Password input (id="password"): DWRUtil.getValue("text") 将返回 Password input 的值;   
  5. Form button (id="formbutton"): DWRUtil.getValue("formbutton") 将返回 Form button 的值;   
  6. Fancy button (id="button"): DWRUtil.getValue("formbutton") 将返回 Fancy button 的值;  


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

 

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

例如: form():

代码
  1.      <input type="textarea" id="textarea" value="1111"/>  
  2.       <input type="text" id="text" value="2222"/>  
  3.       <input type="password" id= "password" value="3333"/>  
  4.       <select id="select">  
  5. <option  value="1"> 苹果 </option>  
  6. <option  value="4444" select> 香蕉 </option>  
  7. <option  value="3"> 鸭梨 </option>  
  8.       </select>  
  9.       <input type="button" id="button" value="5555"/>  
  10.         
  11.         那么: DWRUtil.getValues({textarea:null,select:null,text:null,password:null,button:null})   
  12.         将返回     ^^^^^^^^^^^^^^^^{textarea:1111,select:4444,text:2222,password:3333,button:5555}  



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

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

 

<input type="text" οnkeypress="DWRUtil.onReturn(event, submitFunction)"/>
<input type="button" οnclick="submitFunction()"/>

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

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

在一个input box里选一个范围

代码
  1. DWRUtil.selectRange("sel-test", $("start").value, $("end").value);   
  2.   
  3. 比如:<input type="text" id="sel-test" value="012345678901234567890">   
  4.   
  5. 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请求后,页面显示的提示等待信息;

 

代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值