/********************/
/********************/
util.js contains some useful function function, used to call on the client page.
Main function is as follows:
Code
- 1, $ () access to the page parameter value
- 2, addOptions and removeAllOptions initialize the drop-down box
- 3, addRows and removeAllRows fill forms
- 4, getText made text property value
- 5, getValue form to obtain the value of form
- 6, getValues made form multiple values
- 7, onReturn
- 8, selectRange
- 9, setValue
- 10, setValues
- 11, toDescriptiveString
- 12, useLoadingMessage
- 13, Submission box
************************************************** *******************
////////////////////// http://blog.163.com/fzfx888///////////////// /////////
************************************************** *******************
Code
- 1, $ () function
- IE5.0 does not support
- $ = Document.getElementById
- Form to obtain a form value
- var name = $ ( "name");
************************************************** *********************************
////////////////////////////////////////////////// /////////////////////////////////
************************************************** *********************************
2, used to fill the select drop-down box option
Code
- a, if you want to select in the update, the want to preserve the original data, that is, in the original select to add a new option:
- var sel = DWRUtil.getValue (id);
- DWRUtil.removeAllOptions (id);
- DWRUtil.addOptions (id ,...);
- DWRUtil.setValue (id, sel);
- demo: For instance you want to add an option: "- Please Choose -"
- DWRUtil.addOptions (id ,["-- Please select --"]);
- DWRUtil.addOptions () has 5 methods:
Code
- @ Simple Array Example: a simple array
- For example:
- Array array = new Array [ 'Africa', 'America', 'Asia', 'Australasia', 'Europe'];
- DWRUtil.addOptions ( "demo1", array);
Code
- @ Simple Object Array Example easy array elements for beans
- Under the circumstances, you need to specify the property to display beans and bean corresponding value
- For example:
- public class Person (
- private String name;
- private Integer id;
- pirvate String address;
- public void set () (... ...)
- public String get () (... ...)
- )
- DWRUtil.addOptions ( "demo2", array, 'id', 'name');
- Point to one of id and id of the bean property, optiong at the corresponding value, name of the name point to bean property, the corresponding drop-down box which shows the value.
Code
- @ Advanced Object Array Example basic Ibid
- 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');
Code
- @ Map Example using the map to fill the development of options:
- If the server back Map, so you can deal with this:
- DWRUtil.addOptions ( "demo3", map);
- Value corresponds to one of map keys, text corresponding map values;
Code
- @ <ul> And <ol> list editing
- DWRUtil.addOptions () function can not only fill a select, open can reclaim <ul> and <ol> such elements heml
************************************************** *********************************
/////////////////////////////// fzfx88@163.com ////////////// ////////////////////////
************************************************** *********************************
3, addRows and removeAllRows fill forms
DWR to provide two functions to the operation table;
----------------------------
DWRUtil.addRows (); add a row
----------------------------
DWRUtil.removeAllRows (id); delete the specified id of the table
----------------------------
Focused look at the following addRows () function:
DWRUtil.addRows (id, array, cellfuncs, [options]);
Table corresponds to one of id's id (a more suitable tbodye, recommend the use of tbodye)
array are server-side server return value, such as list, map and so on
cellfuncs and a return value to day-chun form
[options] is used to set the table style, it has two internal function to set the cell style (rowCreator, cellCreator).
Such as: server-side back list, and the list are stored in the following bean:
Code
- public class Person (
- private String name;
- private Integer id;
- pirvate String address;
- public void set () (... ...)
- public String get () (... ...)
- )
Use the following DWRUtil.addRows ();
/************************************************* *****************************/
/****************** *********** Fzfx88@hotmail.com *************** *****************/
/************************************************* ********************************/
Code
- 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");
delButton.setAttribute ( "type", "button");
delButton.onclick = function () (delPerson (idd);); - delButton.setAttribute ( "id", "delete");
- delButton.setAttribute ( "value", "delete");
- return delButton;
- ),
- function (data) (
- var idd = data.id;
- var editButton = document.createElement ( "input");
editButton.setAttribute ( "type", "button");
editButton.onclick = function () (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 + ", 255255)";
- td.style.backgroundColor = "menu";
- td.style.fontWeight = "bold";
- td.style.align = "center";
- return td;
- )
- ));
- document.getElementById ( "bt"). style.display = "none";
- )
To be continued ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
/************************************************* *******************************/
/*********************** QQ: 171505924 Gump ********************** ****************/
/************************************************* *******************************/
4, getText made text property value
DWRUtil.getText (id): used to access option in the text such as:
Code
- <select id="select">
- <option value="1"> apple </ option>
- <option value="2" select> banana </ option>
- <option value="3"> Pear </ option>
- </ select>
Call DWRUtil.getText ( "select"); will return "banana" field;
DWRUtil.getText (id); just select the text are used to obtain the value of the other does not apply.
/************************************************* *****************************/
/************************************************* *****************************/
/************************************************* *****************************/
5, DWRUtil.getValue (id): used to access form values form
Have the following situations:
Code
- Text area (id = "textarea"): DWRUtil.getValue ( "textarea") will return the value of Text area;
- Selection list (id = "select"): DWRUtil.getValue ( "select") will return to the Selection list value;
- Text input (id = "text"): DWRUtil.getValue ( "text") will return the Text input value;
- Password input (id = "password"): DWRUtil.getValue ( "text") will return the value of Password input;
- Form button (id = "formbutton"): DWRUtil.getValue ( "formbutton") will return the value of Form button;
- Fancy button (id = "button"): DWRUtil.getValue ( "formbutton") will return the value of Fancy button;
/************************************************* *****************************/
/************************************************* *****************************/
/************************************************* *****************************/
6, getValues obtain multiple values form bulk access to the page the form values into an array form, return name / value;
For example: form ():
Code
- <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"> apple </ option>
- <option value="4444" select> banana </ option>
- <option value="3"> Pear </ option>
- </ select>
- <input type="button" id="button" value="5555"/>
- Well: DWRUtil.getValues ((textarea: null, select: null, text: null, password: null, button: null))
- Will return ^^^^^^^^^^^^^^^^{ textarea: 1111, select: 4444, text: 2222, password: 3333, button: 5555)
/************************************************* *****************************/
/************************************************* *****************************/
/************************************************* *****************************/
7, DWRUtil.onReturn prevent when in the text box directly press enter on the form submission.
<input type="text" onkeypress="DWRUtil.onReturn(event, submitFunction)"/>
<input type="button"/>
/************************************************* *****************************/
/************************************************* *****************************/
/************************************************* *****************************/
8, DWRUtil.selectRange (ele, start, end);
At an input box where the election of a range of
Code
- DWRUtil.selectRange ( "sel-test", $ ( "start"). Value, $ ( "end"). Value);
- For instance: <input type="text" id="sel-test" value="012345678901234567890">
- DWRUtil.selectRange ( "sel-test", 2, 15);
The results of the text box the value "2345678901234" will be selected '
/************************************************* *****************************/
/************************************************* *****************************/
/************************************************* *****************************/
9, DWRUtil.setValue (id, value);
Id for the specified elements, to set up a new value;
/************************************************* *****************************/
10, DWRUtil.setValues ((
name: "fzfx88",
password: "1234567890"
)
); Ibid., bulk update form values.
/************************************************* *****************************/
11, DWRUtil.toDescriptiveString ()
With debug information toString, first for going to debug the target, the second parameter to deal with grades. Grades are as follows:
0: Single line of debug single debugging
1: Multi-line debug that does not dig into child objects are not sub-element analysis of multi-line debugging
2: Multi-line debug that digs into the 2nd layer of child objects to the second layer up to analysis of sub-elements of the multi-line debugging
<input type="text">
DWRUtil. toDescriptiveString ( "text", 0);
/************************************************* *****************************/
12, DWRUtil.useLoadingMessage ();
When issued by ajax request, the page displays Wait for the prompt information;
Code
- function searchUser () (
- var loadinfo = "loading ....."
- try (
- regUser.queryAllUser (userList);
- DWRUtil.useLoadingMessage (loadinfo);
- ) catch (e) (
- )
- )







